]> 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:14:46 +0000 (21:14 +0000)
committerPeter Edberg <pedberg@unicode.org>
Fri, 30 Sep 2011 21:14:46 +0000 (21:14 +0000)
X-SVN-Rev: 30770

icu4c/source/i18n/calendar.cpp

index 236954e5db645075f59a25f10add507a9c1375b1..7074c325954b6d06dd50a5a50cd179861e68305d 100644 (file)
@@ -1903,18 +1903,18 @@ void Calendar::add(UCalendarDateFields field, int32_t amount, UErrorCode& status
     // appropriate), record the DST_OFFSET before and after the add()
     // operation.  If it has changed, then adjust the millis to
     // compensate.
-    int32_t dst = 0;
+    int32_t prevOffset = 0;
     int32_t hour = 0;
     if (keepHourInvariant) {
-        dst = get(UCAL_DST_OFFSET, status) + get(UCAL_ZONE_OFFSET, status);
+        prevOffset = get(UCAL_DST_OFFSET, status) + get(UCAL_ZONE_OFFSET, status);
         hour = internalGet(UCAL_HOUR_OF_DAY);
     }
 
     setTimeInMillis(getTimeInMillis(status) + delta, status);
 
     if (keepHourInvariant) {
-        dst -= get(UCAL_DST_OFFSET, status) + get(UCAL_ZONE_OFFSET, status);
-        if (dst != 0) {
+        int32_t newOffset = get(UCAL_DST_OFFSET, status) + get(UCAL_ZONE_OFFSET, status);
+        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
@@ -1923,7 +1923,7 @@ void Calendar::add(UCalendarDateFields field, int32_t amount, UErrorCode& status
             // this we make the adjustment only if it actually
             // maintains the hour.
             double t = internalGetTime();
-            setTimeInMillis(t + dst, status);
+            setTimeInMillis(t + prevOffset - newOffset, status);
             if (get(UCAL_HOUR_OF_DAY, status) != hour) {
                 setTimeInMillis(t, status);
             }