ICU 63.1  63.1
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 
195  USystemTimeZoneType zoneType,
196  const char* region,
197  const int32_t* rawOffset,
198  UErrorCode& ec);
199 
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 
293  static TimeZone* U_EXPORT2 detectHostTimeZone();
294 
307  static TimeZone* U_EXPORT2 createDefault(void);
308 
322  static void U_EXPORT2 adoptDefault(TimeZone* zone);
323 
324 #ifndef U_HIDE_SYSTEM_API
325 
335  static void U_EXPORT2 setDefault(const TimeZone& zone);
336 #endif /* U_HIDE_SYSTEM_API */
337 
344  static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
345 
359  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
360  UnicodeString& canonicalID, UErrorCode& status);
361 
377  static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
378  UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
379 
402  static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id,
403  UnicodeString& winid, UErrorCode& status);
404 
431  static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
432  UnicodeString& id, UErrorCode& status);
433 
443  virtual UBool operator==(const TimeZone& that) const;
444 
454  UBool operator!=(const TimeZone& that) const {return !operator==(that);}
455 
480  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
481  uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
482 
503  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
504  uint8_t dayOfWeek, int32_t milliseconds,
505  int32_t monthLength, UErrorCode& status) const = 0;
506 
530  virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
531  int32_t& dstOffset, UErrorCode& ec) const;
532 
540  virtual void setRawOffset(int32_t offsetMillis) = 0;
541 
549  virtual int32_t getRawOffset(void) const = 0;
550 
558  UnicodeString& getID(UnicodeString& ID) const;
559 
573  void setID(const UnicodeString& ID);
574 
584  SHORT = 1,
623  GENERIC_LOCATION
624  };
625 
638 
652  UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
653 
666  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const;
667 
682  UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
683 
718  virtual UBool useDaylightTime(void) const = 0;
719 
733  virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
734 
743  virtual UBool hasSameRules(const TimeZone& other) const;
744 
752  virtual TimeZone* clone(void) const = 0;
753 
760  static UClassID U_EXPORT2 getStaticClassID(void);
761 
773  virtual UClassID getDynamicClassID(void) const = 0;
774 
790  virtual int32_t getDSTSavings() const;
791 
809  static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
810  char *region, int32_t capacity, UErrorCode& status);
811 
812 protected:
813 
819 
826 
832  TimeZone(const TimeZone& source);
833 
839  TimeZone& operator=(const TimeZone& right);
840 
841 #ifndef U_HIDE_INTERNAL_API
842 
851  static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
852 #endif /* U_HIDE_INTERNAL_API */
853 
854 private:
855  friend class ZoneMeta;
856 
857 
858  static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
859 
868  static const char16_t* findID(const UnicodeString& id);
869 
878  static const char16_t* dereferOlsonLink(const UnicodeString& id);
879 
886  static const char16_t* getRegion(const UnicodeString& id);
887 
888  public:
889 #ifndef U_HIDE_INTERNAL_API
890 
898  static const char16_t* getRegion(const UnicodeString& id, UErrorCode& status);
899 #endif /* U_HIDE_INTERNAL_API */
900 
901  private:
912  static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
913  int32_t& minute, int32_t& second);
914 
925  static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
926  UErrorCode& status);
927 
937  static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
938  UBool negative, UnicodeString& id);
939 
940  UnicodeString fID; // this time zone's ID
941 
942  friend class TZEnumeration;
943 };
944 
945 
946 // -------------------------------------
947 
948 inline UnicodeString&
949 TimeZone::getID(UnicodeString& ID) const
950 {
951  ID = fID;
952  return ID;
953 }
954 
955 // -------------------------------------
956 
957 inline void
958 TimeZone::setID(const UnicodeString& ID)
959 {
960  fID = ID;
961 }
963 
964 #endif /* #if !UCONFIG_NO_FORMATTING */
965 
966 #endif //_TIMEZONE
967 //eof
icu::TimeZone::SHORT_COMMONLY_USED
@ SHORT_COMMONLY_USED
Selector for short display name derived from the time zone's fallback name.
Definition: timezone.h:617
icu::TimeZone::detectHostTimeZone
static TimeZone * detectHostTimeZone()
Creates an instance of TimeZone detected from the current host system configuration.
icu::TimeZone::TimeZone
TimeZone(const UnicodeString &id)
Construct a TimeZone with a given ID.
icu::TimeZone::getDSTSavings
virtual int32_t getDSTSavings() const
Returns the amount of time to be added to local standard time to get local wall clock time.
icu::TimeZone::~TimeZone
virtual ~TimeZone()
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::TimeZone::getCanonicalID
static UnicodeString & getCanonicalID(const UnicodeString &id, UnicodeString &canonicalID, UBool &isSystemID, UErrorCode &status)
Returns the canonical system time zone ID or the normalized custom time zone ID for the given time zo...
icu::TimeZone::getOffset
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, uint8_t dayOfWeek, int32_t milliseconds, int32_t monthLength, UErrorCode &status) const =0
Gets the time zone offset, for current date, modified in case of daylight savings.
icu::TimeZone::inDaylightTime
virtual UBool inDaylightTime(UDate date, UErrorCode &status) const =0
Queries if the given date is in daylight savings time in this time zone.
icu::TimeZone::getDisplayName
UnicodeString & getDisplayName(const Locale &locale, UnicodeString &result) const
Returns a name of this time zone suitable for presentation to the user in the specified locale.
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301
icu::TimeZone::setRawOffset
virtual void setRawOffset(int32_t offsetMillis)=0
Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add to GMT to get local time,...
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
icu::TimeZone::SHORT_GENERIC
@ SHORT_GENERIC
Selector for short generic display name.
Definition: timezone.h:594
icu::TimeZone::operator==
virtual UBool operator==(const TimeZone &that) const
Returns true if the two TimeZones are equal.
UResourceBundle
struct UResourceBundle UResourceBundle
Definition: ures.h:59
icu::TimeZone::loadRule
static UResourceBundle * loadRule(const UResourceBundle *top, const UnicodeString &ruleid, UResourceBundle *oldbundle, UErrorCode &status)
Utility function.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::TimeZone::EDisplayType
EDisplayType
Enum for use with getDisplayName.
Definition: timezone.h:579
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:131
icu::TimeZone::TimeZone
TimeZone()
Default constructor.
icu::TimeZone::getStaticClassID
static UClassID getStaticClassID(void)
Return the class ID for this class.
icu::TimeZone::setDefault
static void setDefault(const TimeZone &zone)
Same as adoptDefault(), except that the TimeZone object passed in is NOT adopted; the caller remains ...
icu::TimeZone::TimeZone
TimeZone(const TimeZone &source)
Copy constructor.
icu::TimeZone::getOffset
virtual void getOffset(UDate date, UBool local, int32_t &rawOffset, int32_t &dstOffset, UErrorCode &ec) const
Returns the time zone raw and GMT offset for the given moment in time.
icu::TimeZone::createTimeZoneIDEnumeration
static StringEnumeration * createTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char *region, const int32_t *rawOffset, UErrorCode &ec)
Returns an enumeration over system time zone IDs with the given filter conditions.
icu::TimeZone::getCanonicalID
static UnicodeString & getCanonicalID(const UnicodeString &id, UnicodeString &canonicalID, UErrorCode &status)
Returns the canonical system timezone ID or the normalized custom time zone ID for the given time zon...
icu::TimeZone::adoptDefault
static void adoptDefault(TimeZone *zone)
Sets the default time zone (i.e., what's returned by createDefault()) to be the specified time zone.
icu::TimeZone::getRegion
static const char16_t * getRegion(const UnicodeString &id, UErrorCode &status)
Returns the region code associated with the given zone, or NULL if the zone is not known.
ures.h
C API: Resource Bundle.
icu::TimeZone::getUnknown
static const TimeZone & getUnknown()
Returns the "unknown" time zone.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:290
icu::TimeZone::createDefault
static TimeZone * createDefault(void)
Creates a new copy of the default TimeZone for this host.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
icu::TimeZone::getEquivalentID
static const UnicodeString getEquivalentID(const UnicodeString &id, int32_t index)
Returns an ID in the equivalency group that includes the given ID.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:90
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:401
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:57
icu::TimeZone::getTZDataVersion
static const char * getTZDataVersion(UErrorCode &status)
Returns the timezone data version currently used by ICU.
icu::TimeZone::getRegion
static int32_t getRegion(const UnicodeString &id, char *region, int32_t capacity, UErrorCode &status)
Gets the region code associated with the given system time zone ID.
ucal.h
C API: Calendar.
icu::TimeZone::getOffset
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, uint8_t dayOfWeek, int32_t millis, UErrorCode &status) const =0
Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add to GMT to get loc...
icu::TimeZone::countEquivalentIDs
static int32_t countEquivalentIDs(const UnicodeString &id)
Returns the number of IDs in the equivalency group that includes the given ID.
icu::TimeZone::getGMT
static const TimeZone * getGMT(void)
The GMT (=UTC) time zone has a raw offset of zero and does not use daylight savings time.
icu::TimeZone::getWindowsID
static UnicodeString & getWindowsID(const UnicodeString &id, UnicodeString &winid, UErrorCode &status)
Converts a system time zone ID to an equivalent Windows time zone ID.
icu::TimeZone::createTimeZone
static TimeZone * createTimeZone(const UnicodeString &ID)
Creates a TimeZone for the given ID.
icu::TimeZone::getDynamicClassID
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
icu::TimeZone::createEnumeration
static StringEnumeration * createEnumeration(int32_t rawOffset)
Returns an enumeration over time zone IDs with a given raw offset from GMT.
icu::TimeZone::operator=
TimeZone & operator=(const TimeZone &right)
Default assignment operator.
icu::TimeZone::createEnumeration
static StringEnumeration * createEnumeration(const char *country)
Returns an enumeration over time zone IDs associated with the given country.
icu::TimeZone::createEnumeration
static StringEnumeration * createEnumeration()
Returns an enumeration over all recognized time zone IDs.
icu::TimeZone::getIDForWindowsID
static UnicodeString & getIDForWindowsID(const UnicodeString &winid, const char *region, UnicodeString &id, UErrorCode &status)
Converts a Windows time zone ID to an equivalent system time zone ID for a region.
UDate
double UDate
Date and Time data type.
Definition: utypes.h:203
icu::TimeZone::LONG_GMT
@ LONG_GMT
Selector for long display name derived from time zone offset.
Definition: timezone.h:611
icu::TimeZone::getDisplayName
UnicodeString & getDisplayName(UBool daylight, EDisplayType style, UnicodeString &result) const
Returns a name of this time zone suitable for presentation to the user in the default locale.
icu::TimeZone::SHORT_GMT
@ SHORT_GMT
Selector for short display name derived from time zone offset.
Definition: timezone.h:605
icu::TimeZone::clone
virtual TimeZone * clone(void) const =0
Clones TimeZone objects polymorphically.
icu::TimeZone::useDaylightTime
virtual UBool useDaylightTime(void) const =0
Queries if this time zone uses daylight savings time.
icu::TimeZone::getDisplayName
UnicodeString & getDisplayName(UnicodeString &result) const
Returns a name of this time zone suitable for presentation to the user in the default locale.
icu::TimeZone::LONG_GENERIC
@ LONG_GENERIC
Selector for long generic display name.
Definition: timezone.h:599
icu::TimeZone::hasSameRules
virtual UBool hasSameRules(const TimeZone &other) const
Returns true if this zone has the same rule and offset as another zone.
uobject.h
C++ API: Common ICU base class UObject.
icu::TimeZone::LONG
@ LONG
Selector for long display name.
Definition: timezone.h:589
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
USystemTimeZoneType
USystemTimeZoneType
System time zone type constants used by filtering zones in ucal_openTimeZoneIDEnumeration.
Definition: ucal.h:547
icu::TimeZone::operator!=
UBool operator!=(const TimeZone &that) const
Returns true if the two TimeZones are NOT equal; that is, if operator==() returns false.
Definition: timezone.h:454
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192
icu::TimeZone::getDisplayName
UnicodeString & getDisplayName(UBool daylight, EDisplayType style, const Locale &locale, UnicodeString &result) const
Returns a name of this time zone suitable for presentation to the user in the specified locale.
unistr.h
C++ API: Unicode String.
icu::TimeZone::getRawOffset
virtual int32_t getRawOffset(void) const =0
Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add to GMT to get local ti...