ICU 64.2  64.2
timezone.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*************************************************************************
4 * Copyright (c) 1997-2016, International Business Machines Corporation
5 * and others. All Rights Reserved.
6 **************************************************************************
7 *
8 * File TIMEZONE.H
9 *
10 * Modification History:
11 *
12 * Date Name Description
13 * 04/21/97 aliu Overhauled header.
14 * 07/09/97 helena Changed createInstance to createDefault.
15 * 08/06/97 aliu Removed dependency on internal header for Hashtable.
16 * 08/10/98 stephen Changed getDisplayName() API conventions to match
17 * 08/19/98 stephen Changed createTimeZone() to never return 0
18 * 09/02/98 stephen Sync to JDK 1.2 8/31
19 * - Added getOffset(... monthlen ...)
20 * - Added hasSameRules()
21 * 09/15/98 stephen Added getStaticClassID
22 * 12/03/99 aliu Moved data out of static table into icudata.dll.
23 * Hashtable replaced by new static data structures.
24 * 12/14/99 aliu Made GMT public.
25 * 08/15/01 grhoten Made GMT private and added the getGMT() function
26 **************************************************************************
27 */
28 
29 #ifndef TIMEZONE_H
30 #define TIMEZONE_H
31 
32 #include "unicode/utypes.h"
33 
39 #if !UCONFIG_NO_FORMATTING
40 
41 #include "unicode/uobject.h"
42 #include "unicode/unistr.h"
43 #include "unicode/ures.h"
44 #include "unicode/ucal.h"
45 
47 
48 class StringEnumeration;
49 
131 class U_I18N_API TimeZone : public UObject {
132 public:
136  virtual ~TimeZone();
137 
150  static const TimeZone& U_EXPORT2 getUnknown();
151 
164  static const TimeZone* U_EXPORT2 getGMT(void);
165 
177  static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
178 
194  static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
195  USystemTimeZoneType zoneType,
196  const char* region,
197  const int32_t* rawOffset,
198  UErrorCode& ec);
199 
207  static StringEnumeration* U_EXPORT2 createEnumeration();
208 
226  static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
227 
238  static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
239 
254  static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
255 
275  static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
276  int32_t index);
277 
301  static TimeZone* U_EXPORT2 detectHostTimeZone();
302 
316  static TimeZone* U_EXPORT2 createDefault(void);
317 
331  static void U_EXPORT2 adoptDefault(TimeZone* zone);
332 
333 #ifndef U_HIDE_SYSTEM_API
334 
344  static void U_EXPORT2 setDefault(const TimeZone& zone);
345 #endif /* U_HIDE_SYSTEM_API */
346 
353  static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
354 
368  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
369  UnicodeString& canonicalID, UErrorCode& status);
370 
386  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
387  UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
388 
411  static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id,
412  UnicodeString& winid, UErrorCode& status);
413 
440  static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
441  UnicodeString& id, UErrorCode& status);
442 
452  virtual UBool operator==(const TimeZone& that) const;
453 
463  UBool operator!=(const TimeZone& that) const {return !operator==(that);}
464 
489  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
490  uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
491 
512  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
513  uint8_t dayOfWeek, int32_t milliseconds,
514  int32_t monthLength, UErrorCode& status) const = 0;
515 
539  virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
540  int32_t& dstOffset, UErrorCode& ec) const;
541 
549  virtual void setRawOffset(int32_t offsetMillis) = 0;
550 
558  virtual int32_t getRawOffset(void) const = 0;
559 
567  UnicodeString& getID(UnicodeString& ID) const;
568 
582  void setID(const UnicodeString& ID);
583 
593  SHORT = 1,
632  GENERIC_LOCATION
633  };
634 
646  UnicodeString& getDisplayName(UnicodeString& result) const;
647 
661  UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
662 
675  UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, UnicodeString& result) const;
676 
691  UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
692 
727  virtual UBool useDaylightTime(void) const = 0;
728 
742  virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
743 
752  virtual UBool hasSameRules(const TimeZone& other) const;
753 
761  virtual TimeZone* clone(void) const = 0;
762 
769  static UClassID U_EXPORT2 getStaticClassID(void);
770 
782  virtual UClassID getDynamicClassID(void) const = 0;
783 
799  virtual int32_t getDSTSavings() const;
800 
818  static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
819  char *region, int32_t capacity, UErrorCode& status);
820 
821 protected:
822 
827  TimeZone();
828 
834  TimeZone(const UnicodeString &id);
835 
841  TimeZone(const TimeZone& source);
842 
848  TimeZone& operator=(const TimeZone& right);
849 
850 #ifndef U_HIDE_INTERNAL_API
851 
860  static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
861 #endif /* U_HIDE_INTERNAL_API */
862 
863 private:
864  friend class ZoneMeta;
865 
866 
867  static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
868 
877  static const char16_t* findID(const UnicodeString& id);
878 
887  static const char16_t* dereferOlsonLink(const UnicodeString& id);
888 
895  static const char16_t* getRegion(const UnicodeString& id);
896 
897  public:
898 #ifndef U_HIDE_INTERNAL_API
899 
907  static const char16_t* getRegion(const UnicodeString& id, UErrorCode& status);
908 #endif /* U_HIDE_INTERNAL_API */
909 
910  private:
921  static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
922  int32_t& minute, int32_t& second);
923 
934  static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
935  UErrorCode& status);
936 
946  static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
947  UBool negative, UnicodeString& id);
948 
949  UnicodeString fID; // this time zone's ID
950 
951  friend class TZEnumeration;
952 };
953 
954 
955 // -------------------------------------
956 
957 inline UnicodeString&
959 {
960  ID = fID;
961  return ID;
962 }
963 
964 // -------------------------------------
965 
966 inline void
968 {
969  fID = ID;
970 }
972 
973 #endif /* #if !UCONFIG_NO_FORMATTING */
974 
975 #endif //_TIMEZONE
976 //eof
void setID(const UnicodeString &ID)
Sets the TimeZone's ID to the specified value.
Definition: timezone.h:967
C API: Calendar.
UnicodeString & getID(UnicodeString &ID) const
Fills in "ID" with the TimeZone's ID.
Definition: timezone.h:958
double UDate
Date and Time data type.
Definition: utypes.h:203
C++ API: Unicode String.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:93
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:57
EDisplayType
Enum for use with getDisplayName.
Definition: timezone.h:588
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:131
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
Selector for short display name derived from time zone offset.
Definition: timezone.h:614
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
Selector for short generic display name.
Definition: timezone.h:603
Selector for long generic display name.
Definition: timezone.h:608
Selector for long display name.
Definition: timezone.h:598
C++ API: Common ICU base class UObject.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
Selector for short display name derived from the time zone's fallback name.
Definition: timezone.h:626
USystemTimeZoneType
System time zone type constants used by filtering zones in ucal_openTimeZoneIDEnumeration.
Definition: ucal.h:548
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
struct UResourceBundle UResourceBundle
Definition: ures.h:59
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
Selector for long display name derived from time zone offset.
Definition: timezone.h:620
UBool operator!=(const TimeZone &that) const
Returns true if the two TimeZones are NOT equal; that is, if operator==() returns false...
Definition: timezone.h:463
C API: Resource Bundle.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192