]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/simpletz.cpp
ICU-6.2.21.tar.gz
[apple/icu.git] / icuSources / i18n / simpletz.cpp
index 03b710b36bedbee83a5e94f3e19e9f6569d150ae..393d339d2850bbf447e624814eff5bee1846a7fe 100644 (file)
 
 #include "unicode/simpletz.h"
 #include "unicode/gregocal.h"
-#include "tzdat.h"
 
 U_NAMESPACE_BEGIN
 
-const char SimpleTimeZone::fgClassID = 0; // Value is irrelevant
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleTimeZone)
 
 // WARNING: assumes that no rule is measured from the end of February,
 // since we don't handle leap years. Could handle assuming always
 // Gregorian, since we know they didn't have daylight time when
 // Gregorian calendar started.
-const int8_t SimpleTimeZone::staticMonthLength[] = {31,28,31,30,31,30,31,31,30,31,30,31};
+const int8_t SimpleTimeZone::STATICMONTHLENGTH[] = {31,29,31,30,31,30,31,31,30,31,30,31};
 
 // *****************************************************************************
 // class SimpleTimeZone
@@ -121,40 +120,6 @@ SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
               savingsDST, status);
 }
 
-/**
- * Construct from memory-mapped data.  For private use by TimeZone.
- */
-SimpleTimeZone::SimpleTimeZone(const StandardZone& stdZone,
-                               const UnicodeString& ID)
-:   TimeZone(ID)
-{
-    UErrorCode status = U_ZERO_ERROR;
-    construct(stdZone.gmtOffset,
-              0, 0, 0, 0, WALL_TIME,
-              0, 0, 0, 0, WALL_TIME,
-              0, status);
-}
-
-/**
- * Construct from memory-mapped data.  For private use by TimeZone.
- */
-SimpleTimeZone::SimpleTimeZone(const DSTZone& dstZone,
-                               const UnicodeString& ID)
-:   TimeZone(ID)
-{
-    UErrorCode status = U_ZERO_ERROR;
-    construct(dstZone.gmtOffset,
-              dstZone.onsetRule.month, dstZone.onsetRule.dowim,
-              dstZone.onsetRule.dow,
-              dstZone.onsetRule.time * (int32_t)60000,
-              (TimeMode)dstZone.onsetRule.mode,
-              dstZone.ceaseRule.month, dstZone.ceaseRule.dowim,
-              dstZone.ceaseRule.dow,
-              dstZone.ceaseRule.time * (int32_t)60000,
-              (TimeMode)dstZone.ceaseRule.mode,
-              dstZone.dstSavings * (int32_t)60000, status);
-}
-
 /**
  * Internal construction method.
  */
@@ -403,7 +368,7 @@ int32_t
 SimpleTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
                           uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const
 {
-    // Check the month before indexing into staticMonthLength. This
+    // Check the month before indexing into STATICMONTHLENGTH. This
     // duplicates the test that occurs in the 7-argument getOffset(),
     // however, this is unavoidable. We don't mind because this method, in
     // fact, should not be called; internal code should always call the
@@ -415,14 +380,14 @@ SimpleTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
         return 0;
     }
 
-    return getOffset(era, year, month, day, dayOfWeek, millis, staticMonthLength[month], status);
+    return getOffset(era, year, month, day, dayOfWeek, millis, STATICMONTHLENGTH[month], status);
 }
 
 int32_t 
 SimpleTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
                           uint8_t dayOfWeek, int32_t millis, 
                           int32_t monthLength, UErrorCode& status) const {
-    // Check the month before indexing into staticMonthLength. This
+    // Check the month before indexing into STATICMONTHLENGTH. This
     // duplicates a test that occurs in the 9-argument getOffset(),
     // however, this is unavoidable. We don't mind because this method, in
     // fact, should not be called; internal code should always call the
@@ -436,7 +401,7 @@ SimpleTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
     }
 
     // TODO FIX We don't handle leap years yet!
-    int32_t prevMonthLength = (month >= 1) ? staticMonthLength[month - 1] : 31;
+    int32_t prevMonthLength = (month >= 1) ? STATICMONTHLENGTH[month - 1] : 31;
 
     return getOffset(era, year, month, day, dayOfWeek, millis,
                      monthLength, prevMonthLength, status);
@@ -460,7 +425,9 @@ SimpleTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
         || millis < 0
         || millis >= U_MILLIS_PER_DAY
         || monthLength < 28
-        || monthLength > 31) {
+        || monthLength > 31
+        || prevMonthLength < 28
+        || prevMonthLength > 31) {
         status = U_ILLEGAL_ARGUMENT_ERROR;
         return -1;
     }
@@ -579,7 +546,7 @@ SimpleTimeZone::compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen
         
         // if ruleDay is negative (we assume it's not zero here), we have to do
         // the same calculation figuring backward from the last day of the month.
-        // (staticMonthLength gives us that last day.  We don't take leap years
+        // (STATICMONTHLENGTH gives us that last day.  We don't take leap years
         // into account, so this may not work right for February.)
         else
         {
@@ -855,7 +822,7 @@ SimpleTimeZone::decodeStartRule(UErrorCode& status)
                 status = U_ILLEGAL_ARGUMENT_ERROR;
                 return;
             }
-        } else if (startDay > staticMonthLength[startMonth]) {
+        } else if (startDay > STATICMONTHLENGTH[startMonth]) {
             status = U_ILLEGAL_ARGUMENT_ERROR;
             return;
         }
@@ -910,7 +877,7 @@ SimpleTimeZone::decodeEndRule(UErrorCode& status)
                 status = U_ILLEGAL_ARGUMENT_ERROR;
                 return;
             }
-        } else if (endDay > staticMonthLength[endMonth]) {
+        } else if (endDay > STATICMONTHLENGTH[endMonth]) {
             status = U_ILLEGAL_ARGUMENT_ERROR;
             return;
         }