public static Calendar parseDividendDate ( String date ) { if ( ! Utils . isParseable ( date ) ) { return null ; } date = date . trim ( ) ; SimpleDateFormat format = new SimpleDateFormat ( Utils . getDividendDateFormat ( date ) , Locale . US ) ; format . setTimeZone ( TimeZone . getTimeZone ( YahooFinance . TIMEZONE ) ) ; try { Calendar today = Calendar . getInstance ( TimeZone . getTimeZone ( YahooFinance . TIMEZONE ) ) ; Calendar parsedDate = Calendar . getInstance ( TimeZone . getTimeZone ( YahooFinance . TIMEZONE ) ) ; parsedDate . setTime ( format . parse ( date ) ) ; if ( parsedDate . get ( Calendar . YEAR ) == 1970 ) { // Not really clear which year the dividend date is... making a reasonable guess. int monthDiff = parsedDate . get ( Calendar . MONTH ) - today . get ( Calendar . MONTH ) ; int year = today . get ( Calendar . YEAR ) ; if ( monthDiff > 6 ) { year -= 1 ; } else if ( monthDiff < - 6 ) { year += 1 ; } parsedDate . set ( Calendar . YEAR , year ) ; } return parsedDate ; } catch ( ParseException ex ) { log . warn ( "Failed to parse dividend date: " + date ) ; log . debug ( "Failed to parse dividend date: " + date , ex ) ; return null ; } }
Used to parse the dividend dates . Returns null if the date cannot be parsed .