Browse files

Use GregorianCalendar for quarter calculation

  • Loading branch information...
1 parent 3e38cf1 commit 4fd7fd0671b2c86f9fac7a7963ec6607ad414195 @botic botic committed Sep 11, 2013
Showing with 20 additions and 1 deletion.
  1. +20 −1 modules/ringo/utils/dates.js
View
21 modules/ringo/utils/dates.js
@@ -309,7 +309,26 @@ function daysInFebruary(date) {
* @returns Number quarter of the year, between 1 and 4.
*/
function quarterInYear(date) {
- return Math.floor((date.getMonth() / 3) + 1);
+ switch (createGregorianCalender(date).get(java.util.Calendar.MONTH)) {
+ case java.util.Calendar.JANUARY:
+ case java.util.Calendar.FEBRUARY:
+ case java.util.Calendar.MARCH:
+ return 1;
+ case java.util.Calendar.APRIL :
+ case java.util.Calendar.MAY :
+ case java.util.Calendar.JUNE :
+ return 2;
+ case java.util.Calendar.JULY :
+ case java.util.Calendar.AUGUST :
+ case java.util.Calendar.SEPTEMBER :
+ return 3;
+ case java.util.Calendar.OCTOBER :
+ case java.util.Calendar.NOVEMBER :
+ case java.util.Calendar.DECEMBER :
+ return 4;
+ }
+
+ throw "Invalid date provided";
}
/**

0 comments on commit 4fd7fd0

Please sign in to comment.