ISSUE-115 datePart('month') should return January as 1 not 0

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1161 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-08-16 16:09:39 +00:00
parent a90a9c724e
commit bb7d3c388c

View File

@ -24,7 +24,6 @@ public class DatePart implements Function {
} else { } else {
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.setTime((Date) args[0]); c.setTime((Date) args[0]);
return getPart(c, part); return getPart(c, part);
} }
} }
@ -42,23 +41,18 @@ public class DatePart implements Function {
return c.get(Calendar.MINUTE); return c.get(Calendar.MINUTE);
} else if ("seconds".equals(part) || "sec".equals(part) || "s".equals(part)) { } else if ("seconds".equals(part) || "sec".equals(part) || "s".equals(part)) {
return c.get(Calendar.SECOND); return c.get(Calendar.SECOND);
} else if ("years".equals(part) || "year".equals(part)) { } else if ("years".equals(part) || "year".equals(part)) {
return c.get(Calendar.YEAR); return c.get(Calendar.YEAR);
} else if ("months".equals(part) || "month".equals(part)) { // avoid 'm' to avoid confusion with minute } else if ("months".equals(part) || "month".equals(part)) { // avoid 'm' to avoid confusion with minute
return c.get(Calendar.MONTH); return c.get(Calendar.MONTH) + 1; // ISSUE 115 - people expect January to be 1 not 0
} else if ("weeks".equals(part) || "week".equals(part) || "w".equals(part)) { } else if ("weeks".equals(part) || "week".equals(part) || "w".equals(part)) {
return c.get(Calendar.WEEK_OF_MONTH); return c.get(Calendar.WEEK_OF_MONTH);
} else if ("days".equals(part) || "day".equals(part) || "d".equals(part)) { } else if ("days".equals(part) || "day".equals(part) || "d".equals(part)) {
return c.get(Calendar.DAY_OF_MONTH); return c.get(Calendar.DAY_OF_MONTH);
} else if ("weekday".equals(part)) { } else if ("weekday".equals(part)) {
int r = c.get(Calendar.DAY_OF_WEEK); return s_daysOfWeek[c.get(Calendar.DAY_OF_WEEK)];
return s_daysOfWeek[r];
} else if ("time".equals(part)) { } else if ("time".equals(part)) {
return c.getTimeInMillis(); return c.getTimeInMillis();
} else { } else {
return new EvalError("Date unit '" + part + "' not recognized."); return new EvalError("Date unit '" + part + "' not recognized.");
} }