addressed Sattam's comments, and fixed bugs introduced by the previous fix
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
index 26293e9..8c21bad 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
@@ -55,9 +55,9 @@
public static final int[] DAYS_SINCE_MONTH_BEGIN_ORDI = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
- public static final int CHRONON_OF_SECOND = 1000;
- public static final int CHRONON_OF_MINUTE = 60 * CHRONON_OF_SECOND;
- public static final int CHRONON_OF_HOUR = 60 * CHRONON_OF_MINUTE;
+ public static final long CHRONON_OF_SECOND = 1000;
+ public static final long CHRONON_OF_MINUTE = 60 * CHRONON_OF_SECOND;
+ public static final long CHRONON_OF_HOUR = 60 * CHRONON_OF_MINUTE;
public static final long CHRONON_OF_DAY = 24 * CHRONON_OF_HOUR;
public static final int MONTHS_IN_A_YEAR = 12;
@@ -236,9 +236,9 @@
*/
public int getChronon(int hour, int min, int sec, int millis, int timezone) {
// Added milliseconds for all fields but month and day
- int chrononTime = (hour - timezone / 4) * CHRONON_OF_HOUR + (min - (timezone % 4) * 15) * CHRONON_OF_MINUTE
+ long chrononTime = (hour - timezone / 4) * CHRONON_OF_HOUR + (min - (timezone % 4) * 15) * CHRONON_OF_MINUTE
+ sec * CHRONON_OF_SECOND + millis;
- return chrononTime;
+ return (int)chrononTime;
}
public long adjustChrononByTimezone(long chronon, int timezone) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
index c6da17e..b343f63 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
@@ -187,8 +187,9 @@
if (day < 0) {
boolean isLeapYear = calInstanct.isLeapYear(year1);
- day += (isLeapYear) ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[month1 - 2])
- : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[month1 - 2]);
+ // need to "borrow" the days in previous month to make the day positive; when month is 1 (Jan), Dec will be borrowed
+ day += (isLeapYear) ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[(12 + month1 - 2) % 12])
+ : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[(12 + month1 - 2) % 12]);
month -= 1;
}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDurationFromDateTimeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDurationFromDateTimeDescriptor.java
index e09f1da..a934473 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDurationFromDateTimeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDurationFromDateTimeDescriptor.java
@@ -201,8 +201,9 @@
if (day < 0) {
boolean isLeapYear = calInstanct.isLeapYear(year1);
- day += (isLeapYear) ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[month1 - 2])
- : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[month1 - 2]);
+ // need to "borrow" the days in previous month to make the day positive; when month is 1 (Jan), Dec will be borrowed
+ day += (isLeapYear) ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[(12 + month1 - 2) % 12])
+ : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[(12 + month1 - 2) % 12]);
month -= 1;
}