]> granicus.if.org Git - icu/commitdiff
ICU-8753 Replace confusing use of dst variable with prevOffset / newOffset
authorPeter Edberg <pedberg@unicode.org>
Fri, 30 Sep 2011 21:32:41 +0000 (21:32 +0000)
committerPeter Edberg <pedberg@unicode.org>
Fri, 30 Sep 2011 21:32:41 +0000 (21:32 +0000)
X-SVN-Rev: 30772

icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java

index 55b170b570660f23e5101d3f2e30712446e7ab1d..9fd3413c57d9c7e80f14db47d944c561dbadf28e 100644 (file)
@@ -3076,30 +3076,30 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
         }
 
         // In order to keep the hour invariant (for fields where this is
-        // appropriate), record the DST_OFFSET before and after the add()
-        // operation.  If it has changed, then adjust the millis to
-        // compensate.
-        int dst = 0;
+        // appropriate), check the combined DST & ZONE offset before and
+        // after the add() operation. If it changes, then adjust the millis
+        // to compensate.
+        int prevOffset = 0;
         int hour = 0;
         if (keepHourInvariant) {
-            dst = get(DST_OFFSET) + get(ZONE_OFFSET);
+            prevOffset = get(DST_OFFSET) + get(ZONE_OFFSET);
             hour = internalGet(HOUR_OF_DAY);
         }
 
         setTimeInMillis(getTimeInMillis() + delta);
 
         if (keepHourInvariant) {
-            dst -= get(DST_OFFSET) + get(ZONE_OFFSET);
-            if (dst != 0) {
+            int newOffset = get(DST_OFFSET) + get(ZONE_OFFSET);
+            if (newOffset != prevOffset) {
                 // We have done an hour-invariant adjustment but the
-                // DST offset has altered.  We adjust millis to keep
-                // the hour constant.  In cases such as midnight after
+                // combined offset has changed. We adjust millis to keep
+                // the hour constant. In cases such as midnight after
                 // a DST change which occurs at midnight, there is the
-                // danger of adjusting into a different day.  To avoid
+                // danger of adjusting into a different day. To avoid
                 // this we make the adjustment only if it actually
                 // maintains the hour.
                 long t = time;
-                setTimeInMillis(time + dst);
+                setTimeInMillis(time + prevOffset - newOffset);
                 if (get(HOUR_OF_DAY) != hour) {
                     setTimeInMillis(t);
                 }