00001 /* 00002 * Copyright © {1997-1999}, International Business Machines Corporation and others. All Rights Reserved. 00003 ******************************************************************************** 00004 * 00005 * File TIMEZONE.H 00006 * 00007 * Modification History: 00008 * 00009 * Date Name Description 00010 * 04/21/97 aliu Overhauled header. 00011 * 07/09/97 helena Changed createInstance to createDefault. 00012 * 08/06/97 aliu Removed dependency on internal header for Hashtable. 00013 * 08/10/98 stephen Changed getDisplayName() API conventions to match 00014 * 08/19/98 stephen Changed createTimeZone() to never return 0 00015 * 09/02/98 stephen Sync to JDK 1.2 8/31 00016 * - Added getOffset(... monthlen ...) 00017 * - Added hasSameRules() 00018 * 09/15/98 stephen Added getStaticClassID 00019 * 12/03/99 aliu Moved data out of static table into icudata.dll. 00020 * Hashtable replaced by new static data structures. 00021 * 12/14/99 aliu Made GMT public. 00022 ******************************************************************************** 00023 */ 00024 00025 #ifndef TIMEZONE_H 00026 #define TIMEZONE_H 00027 00028 00029 #include "unicode/unistr.h" 00030 #include "unicode/locid.h" 00031 00032 #include "unicode/udata.h" 00033 00034 class SimpleTimeZone; 00035 struct TZHeader; 00036 struct OffsetIndex; 00037 00112 class U_I18N_API TimeZone { 00113 public: 00117 virtual ~TimeZone(); 00118 00123 static const TimeZone* GMT; 00124 00136 static TimeZone* createTimeZone(const UnicodeString& ID); 00137 00159 static const UnicodeString** const createAvailableIDs(int32_t rawOffset, int32_t& numIDs); 00160 00172 static const UnicodeString** const createAvailableIDs(int32_t& numIDs); 00173 00186 static TimeZone* createDefault(void); 00187 00197 static void adoptDefault(TimeZone* zone); 00198 00206 static void setDefault(const TimeZone& zone); 00207 00217 virtual UBool operator==(const TimeZone& that) const; 00218 00228 UBool operator!=(const TimeZone& that) const {return !operator==(that);} 00229 00249 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, 00250 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0; 00254 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, 00255 uint8_t dayOfWeek, int32_t millis) const = 0; 00256 00271 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, 00272 uint8_t dayOfWeek, int32_t milliseconds, 00273 int32_t monthLength, UErrorCode& status) const = 0; 00274 00282 virtual void setRawOffset(int32_t offsetMillis) = 0; 00283 00291 virtual int32_t getRawOffset(void) const = 0; 00292 00300 UnicodeString& getID(UnicodeString& ID) const; 00301 00315 void setID(const UnicodeString& ID); 00316 00321 enum EDisplayType { 00322 SHORT = 1, 00323 LONG 00324 }; 00325 00336 UnicodeString& getDisplayName(UnicodeString& result) const; 00337 00350 UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const; 00351 00363 UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const; 00364 00378 UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const; 00379 00386 virtual UBool useDaylightTime(void) const = 0; 00387 00396 virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0; 00397 00406 virtual UBool hasSameRules(const TimeZone& other) const; 00407 00415 virtual TimeZone* clone(void) const = 0; 00416 00428 static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } 00429 00445 virtual UClassID getDynamicClassID(void) const = 0; 00446 00447 protected: 00448 00453 TimeZone(); 00454 00459 TimeZone(const TimeZone& source); 00460 00465 TimeZone& operator=(const TimeZone& right); 00466 00467 private: 00468 static char fgClassID; 00469 00470 static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string. 00471 00472 static TimeZone* fgDefaultZone; // default time zone (lazy evaluated) 00473 00474 static const UnicodeString GMT_ID; 00475 static const int32_t GMT_ID_LENGTH; 00476 static const UnicodeString CUSTOM_ID; 00477 00479 // Pointers into memory-mapped icudata. Writing to this memory 00480 // will segfault! See tzdat.h for more details. 00482 00488 static const TZHeader * DATA; 00489 00495 static const uint32_t* INDEX_BY_ID; 00496 00502 static const OffsetIndex* INDEX_BY_OFFSET; 00503 00505 // Other system zone data structures 00507 00512 static UnicodeString* ZONE_IDS; 00513 00520 static UBool DATA_LOADED; 00521 00527 static UMTX LOCK; 00528 00534 static void initDefault(void); 00535 00536 // See source file for documentation 00537 static void loadZoneData(void); 00538 00539 // See source file for documentation 00540 static UBool U_CALLCONV isDataAcceptable(void *context, 00541 const char *type, const char *name, 00542 const UDataInfo *pInfo); 00543 00544 // See source file for documentation 00545 static TimeZone* createSystemTimeZone(const UnicodeString& name); 00546 00547 UnicodeString fID; // this time zone's ID 00548 }; 00549 00550 00551 // ------------------------------------- 00552 00553 inline UnicodeString& 00554 TimeZone::getID(UnicodeString& ID) const 00555 { 00556 ID = fID; 00557 return ID; 00558 } 00559 00560 // ------------------------------------- 00561 00562 inline void 00563 TimeZone::setID(const UnicodeString& ID) 00564 { 00565 fID = ID; 00566 } 00567 00568 #endif //_TIMEZONE 00569 //eof