[ASTERIXDB-2352][FUN] Incorrect leap year handling in duration arithmetic

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- DurationArithmeticOperations.addDuration() incorrectly handled leap year

Change-Id: I01e1417f4704d72a4650ec4f2fa257f044a20a09
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2561
Reviewed-by: Till Westmann <tillw@apache.org>
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/DurationArithmeticOperations.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/DurationArithmeticOperations.java
index a50adc6..26c3fb3 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/DurationArithmeticOperations.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/DurationArithmeticOperations.java
@@ -85,13 +85,13 @@
         boolean isLeapYear = GREG_CAL.isLeapYear(year);
 
         if (isLeapYear) {
-            if (day > GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[month - 1]) {
-                day = GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[month - 1];
-            }
-        } else {
             if (day > GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[month - 1]) {
                 day = GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[month - 1];
             }
+        } else {
+            if (day > GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[month - 1]) {
+                day = GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[month - 1];
+            }
         }
 
         return GREG_CAL.getChronon(year, month, day, hour, min, sec, ms, 0) + dayTimeDuration;