ICU 4.4.2 4.4.2
timezone.h
Go to the documentation of this file.
00001 /*************************************************************************
00002 * Copyright (c) 1997-2010, International Business Machines Corporation
00003 * and others. All Rights Reserved.
00004 **************************************************************************
00005 *
00006 * File TIMEZONE.H
00007 *
00008 * Modification History:
00009 *
00010 *   Date        Name        Description
00011 *   04/21/97    aliu        Overhauled header.
00012 *   07/09/97    helena      Changed createInstance to createDefault.
00013 *   08/06/97    aliu        Removed dependency on internal header for Hashtable.
00014 *   08/10/98    stephen        Changed getDisplayName() API conventions to match
00015 *   08/19/98    stephen        Changed createTimeZone() to never return 0
00016 *   09/02/98    stephen        Sync to JDK 1.2 8/31
00017 *                            - Added getOffset(... monthlen ...)
00018 *                            - Added hasSameRules()
00019 *   09/15/98    stephen        Added getStaticClassID
00020 *   12/03/99    aliu        Moved data out of static table into icudata.dll.
00021 *                           Hashtable replaced by new static data structures.
00022 *   12/14/99    aliu        Made GMT public.
00023 *   08/15/01    grhoten     Made GMT private and added the getGMT() function
00024 **************************************************************************
00025 */
00026 
00027 #ifndef TIMEZONE_H
00028 #define TIMEZONE_H
00029 
00030 #include "unicode/utypes.h"
00031 
00037 #if !UCONFIG_NO_FORMATTING
00038 
00039 #include "unicode/uobject.h"
00040 #include "unicode/unistr.h"
00041 #include "unicode/ures.h"
00042 
00043 U_NAMESPACE_BEGIN
00044 
00045 class StringEnumeration;
00046 
00122 class U_I18N_API TimeZone : public UObject {
00123 public:
00127     virtual ~TimeZone();
00128 
00135     static const TimeZone* U_EXPORT2 getGMT(void);
00136 
00147     static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
00148 
00156     static StringEnumeration* U_EXPORT2 createEnumeration();
00157 
00175     static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
00176 
00187     static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
00188 
00203     static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
00204 
00224     static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
00225                                                int32_t index);
00226 
00239     static TimeZone* U_EXPORT2 createDefault(void);
00240 
00250     static void U_EXPORT2 adoptDefault(TimeZone* zone);
00251 
00259     static void U_EXPORT2 setDefault(const TimeZone& zone);
00260 
00267     static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
00268 
00282     static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
00283         UnicodeString& canonicalID, UErrorCode& status);
00284 
00300     static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
00301         UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
00302 
00312     virtual UBool operator==(const TimeZone& that) const;
00313 
00323     UBool operator!=(const TimeZone& that) const {return !operator==(that);}
00324 
00349     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
00350                               uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
00351 
00372     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
00373                            uint8_t dayOfWeek, int32_t milliseconds,
00374                            int32_t monthLength, UErrorCode& status) const = 0;
00375 
00399     virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
00400                            int32_t& dstOffset, UErrorCode& ec) const;
00401 
00409     virtual void setRawOffset(int32_t offsetMillis) = 0;
00410 
00418     virtual int32_t getRawOffset(void) const = 0;
00419 
00427     UnicodeString& getID(UnicodeString& ID) const;
00428 
00442     void setID(const UnicodeString& ID);
00443 
00448     enum EDisplayType {
00453         SHORT = 1,
00458         LONG,
00463         SHORT_GENERIC,
00468         LONG_GENERIC,
00474         SHORT_GMT,
00480         LONG_GMT,
00486         SHORT_COMMONLY_USED,
00492         GENERIC_LOCATION
00493     };
00494 
00506     UnicodeString& getDisplayName(UnicodeString& result) const;
00507 
00521     UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
00522 
00535     UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const;
00536 
00551     UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
00552     
00559     virtual UBool useDaylightTime(void) const = 0;
00560 
00574     virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
00575 
00584     virtual UBool hasSameRules(const TimeZone& other) const;
00585 
00593     virtual TimeZone* clone(void) const = 0;
00594 
00601     static UClassID U_EXPORT2 getStaticClassID(void);
00602 
00614     virtual UClassID getDynamicClassID(void) const = 0;
00615     
00631     virtual int32_t getDSTSavings() const;
00632 
00633 protected:
00634 
00639     TimeZone();
00640 
00646     TimeZone(const UnicodeString &id);
00647 
00653     TimeZone(const TimeZone& source);
00654 
00660     TimeZone& operator=(const TimeZone& right);
00661 
00671     static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
00672 
00673 private:
00674     friend class ZoneMeta;
00675 
00676 
00677     static TimeZone*        createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
00678 
00687     static const UChar* dereferOlsonLink(const UnicodeString& id);
00688 
00694     static const UChar* getRegion(const UnicodeString& id);
00695 
00706     static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
00707         int32_t& min, int32_t& sec);
00708 
00719     static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
00720         UErrorCode& status);
00721 
00731     static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
00732         UBool negative, UnicodeString& id);
00733 
00739     static void             initDefault(void);
00740 
00741     // See source file for documentation
00749     static TimeZone*        createSystemTimeZone(const UnicodeString& name);
00750 
00751     UnicodeString           fID;    // this time zone's ID
00752 
00753 };
00754 
00755 
00756 // -------------------------------------
00757 
00758 inline UnicodeString&
00759 TimeZone::getID(UnicodeString& ID) const
00760 {
00761     ID = fID;
00762     return ID;
00763 }
00764 
00765 // -------------------------------------
00766 
00767 inline void
00768 TimeZone::setID(const UnicodeString& ID)
00769 {
00770     fID = ID;
00771 }
00772 U_NAMESPACE_END
00773 
00774 #endif /* #if !UCONFIG_NO_FORMATTING */
00775 
00776 #endif //_TIMEZONE
00777 //eof
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines