Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sstrickx committed Jan 25, 2015
2 parents 678e282 + bd23225 commit ecd6afd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Binary file removed dist/YahooFinanceAPI-1.0.1.zip
Binary file not shown.
Binary file added dist/YahooFinanceAPI-1.1.0.zip
Binary file not shown.
17 changes: 16 additions & 1 deletion src/yahoofinance/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public static double getDouble(String data) {
data = data.substring(0, data.length() - 1);
multiplier = 1000000;
break;
case 'K':
data = data.substring(0, data.length() - 1);
multiplier = 1000;
break;
}
result = Double.parseDouble(data) * multiplier;
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -101,6 +105,8 @@ public static double getPercent(double numerator, double denominator) {
private static String getDividendDateFormat(String date) {
if(date.matches("[0-9][0-9]-...-[0-9][0-9]")) {
return "dd-MMM-yy";
} else if(date.matches("[0-9]-...-[0-9][0-9]")) {
return "d-MMM-yy";
} else {
return "MMM d";
}
Expand All @@ -116,6 +122,7 @@ public static Calendar parseDividendDate(String date) {
if (!Utils.isParseable(date)) {
return null;
}
date = date.trim();
SimpleDateFormat format = new SimpleDateFormat(Utils.getDividendDateFormat(date));
format.setTimeZone(TimeZone.getTimeZone(YahooFinance.TIMEZONE));
try {
Expand All @@ -124,7 +131,15 @@ public static Calendar parseDividendDate(String date) {
parsedDate.setTime(format.parse(date));

if(parsedDate.get(Calendar.YEAR) == 1970) {
parsedDate.set(Calendar.YEAR, today.get(Calendar.YEAR));
// 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;
Expand Down

0 comments on commit ecd6afd

Please sign in to comment.