ICU 51.2  51.2
timezone.h
Go to the documentation of this file.
1 /*************************************************************************
2 * Copyright (c) 1997-2013, International Business Machines Corporation
3 * and others. All Rights Reserved.
4 **************************************************************************
5 *
6 * File TIMEZONE.H
7 *
8 * Modification History:
9 *
10 * Date Name Description
11 * 04/21/97 aliu Overhauled header.
12 * 07/09/97 helena Changed createInstance to createDefault.
13 * 08/06/97 aliu Removed dependency on internal header for Hashtable.
14 * 08/10/98 stephen Changed getDisplayName() API conventions to match
15 * 08/19/98 stephen Changed createTimeZone() to never return 0
16 * 09/02/98 stephen Sync to JDK 1.2 8/31
17 * - Added getOffset(... monthlen ...)
18 * - Added hasSameRules()
19 * 09/15/98 stephen Added getStaticClassID
20 * 12/03/99 aliu Moved data out of static table into icudata.dll.
21 * Hashtable replaced by new static data structures.
22 * 12/14/99 aliu Made GMT public.
23 * 08/15/01 grhoten Made GMT private and added the getGMT() function
24 **************************************************************************
25 */
26 
27 #ifndef TIMEZONE_H
28 #define TIMEZONE_H
29 
30 #include "unicode/utypes.h"
31 
37 #if !UCONFIG_NO_FORMATTING
38 
39 #include "unicode/uobject.h"
40 #include "unicode/unistr.h"
41 #include "unicode/ures.h"
42 #include "unicode/ucal.h"
43 
45 
46 class StringEnumeration;
47 
129 class U_I18N_API TimeZone : public UObject {
130 public:
134  virtual ~TimeZone();
135 
148  static const TimeZone& U_EXPORT2 getUnknown();
149 
162  static const TimeZone* U_EXPORT2 getGMT(void);
163 
175  static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
176 
192  static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
193  USystemTimeZoneType zoneType,
194  const char* region,
195  const int32_t* rawOffset,
196  UErrorCode& ec);
197 
205  static StringEnumeration* U_EXPORT2 createEnumeration();
206 
224  static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
225 
236  static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
237 
252  static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
253 
273  static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
274  int32_t index);
275 
288  static TimeZone* U_EXPORT2 createDefault(void);
289 
299  static void U_EXPORT2 adoptDefault(TimeZone* zone);
300 
301 #ifndef U_HIDE_SYSTEM_API
302 
310  static void U_EXPORT2 setDefault(const TimeZone& zone);
311 #endif /* U_HIDE_SYSTEM_API */
312 
319  static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
320 
334  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
335  UnicodeString& canonicalID, UErrorCode& status);
336 
352  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
353  UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
354 
364  virtual UBool operator==(const TimeZone& that) const;
365 
375  UBool operator!=(const TimeZone& that) const {return !operator==(that);}
376 
401  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
402  uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
403 
424  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
425  uint8_t dayOfWeek, int32_t milliseconds,
426  int32_t monthLength, UErrorCode& status) const = 0;
427 
451  virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
452  int32_t& dstOffset, UErrorCode& ec) const;
453 
461  virtual void setRawOffset(int32_t offsetMillis) = 0;
462 
470  virtual int32_t getRawOffset(void) const = 0;
471 
479  UnicodeString& getID(UnicodeString& ID) const;
480 
494  void setID(const UnicodeString& ID);
495 
505  SHORT = 1,
544  GENERIC_LOCATION
545  };
546 
558  UnicodeString& getDisplayName(UnicodeString& result) const;
559 
573  UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
574 
587  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const;
588 
603  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
604 
639  virtual UBool useDaylightTime(void) const = 0;
640 
654  virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
655 
664  virtual UBool hasSameRules(const TimeZone& other) const;
665 
673  virtual TimeZone* clone(void) const = 0;
674 
681  static UClassID U_EXPORT2 getStaticClassID(void);
682 
694  virtual UClassID getDynamicClassID(void) const = 0;
695 
711  virtual int32_t getDSTSavings() const;
712 
730  static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
731  char *region, int32_t capacity, UErrorCode& status);
732 
733 protected:
734 
739  TimeZone();
740 
746  TimeZone(const UnicodeString &id);
747 
753  TimeZone(const TimeZone& source);
754 
760  TimeZone& operator=(const TimeZone& right);
761 
762 #ifndef U_HIDE_INTERNAL_API
763 
772  static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
773 #endif /* U_HIDE_INTERNAL_API */
774 
775 private:
776  friend class ZoneMeta;
777 
778 
779  static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
780 
789  static const UChar* findID(const UnicodeString& id);
790 
799  static const UChar* dereferOlsonLink(const UnicodeString& id);
800 
807  static const UChar* getRegion(const UnicodeString& id);
808 
816  static const UChar* getRegion(const UnicodeString& id, UErrorCode& status);
817 
828  static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
829  int32_t& minute, int32_t& second);
830 
841  static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
842  UErrorCode& status);
843 
853  static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
854  UBool negative, UnicodeString& id);
855 
861  static void initDefault(void);
862 
863  // See source file for documentation
871  static TimeZone* createSystemTimeZone(const UnicodeString& name);
872  static TimeZone* createSystemTimeZone(const UnicodeString& name, UErrorCode& ec);
873 
874  UnicodeString fID; // this time zone's ID
875 
876  friend class TZEnumeration;
877 };
878 
879 
880 // -------------------------------------
881 
882 inline UnicodeString&
883 TimeZone::getID(UnicodeString& ID) const
884 {
885  ID = fID;
886  return ID;
887 }
888 
889 // -------------------------------------
890 
891 inline void
892 TimeZone::setID(const UnicodeString& ID)
893 {
894  fID = ID;
895 }
897 
898 #endif /* #if !UCONFIG_NO_FORMATTING */
899 
900 #endif //_TIMEZONE
901 //eof