ICU 57.1 57.1
timezone.h
Go to the documentation of this file.
1/*************************************************************************
2* Copyright (c) 1997-2016, 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
47
130public:
134 virtual ~TimeZone();
135
149
162 static const TimeZone* U_EXPORT2 getGMT(void);
163
176
194 const char* region,
195 const int32_t* rawOffset,
196 UErrorCode& ec);
197
206
225
236 static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
237
252 static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
253
274 int32_t index);
275
290
304
319
320#ifndef U_HIDE_SYSTEM_API
331 static void U_EXPORT2 setDefault(const TimeZone& zone);
332#endif /* U_HIDE_SYSTEM_API */
333
341
357
375
400
427 static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
429
439 virtual UBool operator==(const TimeZone& that) const;
440
450 UBool operator!=(const TimeZone& that) const {return !operator==(that);}
451
476 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
477 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
478
499 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
500 uint8_t dayOfWeek, int32_t milliseconds,
501 int32_t monthLength, UErrorCode& status) const = 0;
502
526 virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
527 int32_t& dstOffset, UErrorCode& ec) const;
528
536 virtual void setRawOffset(int32_t offsetMillis) = 0;
537
545 virtual int32_t getRawOffset(void) const = 0;
546
554 UnicodeString& getID(UnicodeString& ID) const;
555
569 void setID(const UnicodeString& ID);
570
621
634
649
663
679
714 virtual UBool useDaylightTime(void) const = 0;
715
730
739 virtual UBool hasSameRules(const TimeZone& other) const;
740
748 virtual TimeZone* clone(void) const = 0;
749
757
769 virtual UClassID getDynamicClassID(void) const = 0;
770
786 virtual int32_t getDSTSavings() const;
787
805 static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
806 char *region, int32_t capacity, UErrorCode& status);
807
808protected:
809
815
822
828 TimeZone(const TimeZone& source);
829
836
837#ifndef U_HIDE_INTERNAL_API
848#endif /* U_HIDE_INTERNAL_API */
849
850private:
851 friend class ZoneMeta;
852
853
854 static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
855
864 static const UChar* findID(const UnicodeString& id);
865
874 static const UChar* dereferOlsonLink(const UnicodeString& id);
875
882 static const UChar* getRegion(const UnicodeString& id);
883
884 public:
885#ifndef U_HIDE_INTERNAL_API
894 static const UChar* getRegion(const UnicodeString& id, UErrorCode& status);
895#endif /* U_HIDE_INTERNAL_API */
896
897 private:
908 static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
909 int32_t& minute, int32_t& second);
910
921 static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
923
933 static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
935
936 UnicodeString fID; // this time zone's ID
937
938 friend class TZEnumeration;
939};
940
941
942// -------------------------------------
943
944inline UnicodeString&
946{
947 ID = fID;
948 return ID;
949}
950
951// -------------------------------------
952
953inline void
955{
956 fID = ID;
957}
959
960#endif /* #if !UCONFIG_NO_FORMATTING */
961
962#endif //_TIMEZONE
963//eof
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:185
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:55
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:129
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...
virtual UBool useDaylightTime(void) const =0
Queries if this time zone uses daylight savings time.
virtual int32_t getDSTSavings() const
Returns the amount of time to be added to local standard time to get local wall clock time.
virtual ~TimeZone()
static TimeZone * createTimeZone(const UnicodeString &ID)
Creates a TimeZone for the given ID.
EDisplayType
Enum for use with getDisplayName.
Definition timezone.h:575
@ LONG
Selector for long display name.
Definition timezone.h:585
@ SHORT_COMMONLY_USED
Selector for short display name derived from the time zone's fallback name.
Definition timezone.h:613
@ SHORT_GENERIC
Selector for short generic display name.
Definition timezone.h:590
@ LONG_GMT
Selector for long display name derived from time zone offset.
Definition timezone.h:607
@ LONG_GENERIC
Selector for long generic display name.
Definition timezone.h:595
@ SHORT_GMT
Selector for short display name derived from time zone offset.
Definition timezone.h:601
static int32_t countEquivalentIDs(const UnicodeString &id)
Returns the number of IDs in the equivalency group that includes the given ID.
void setID(const UnicodeString &ID)
Sets the TimeZone's ID to the specified value.
Definition timezone.h:954
static const TimeZone & getUnknown()
Returns the "unknown" time zone.
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.
static void setDefault(const TimeZone &zone)
Same as adoptDefault(), except that the TimeZone object passed in is NOT adopted; the caller remains ...
virtual UBool operator==(const TimeZone &that) const
Returns true if the two TimeZones are equal.
static UnicodeString & getWindowsID(const UnicodeString &id, UnicodeString &winid, UErrorCode &status)
Converts a system time zone ID to an equivalent Windows time zone ID.
static TimeZone * detectHostTimeZone()
Creates an instance of TimeZone detected from the current host system configuration.
static UClassID getStaticClassID(void)
Return the class ID for this class.
TimeZone & operator=(const TimeZone &right)
Default assignment operator.
static StringEnumeration * createEnumeration()
Returns an enumeration over all recognized time zone IDs.
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...
virtual UBool hasSameRules(const TimeZone &other) const
Returns true if this zone has the same rule and offset as another zone.
TimeZone(const UnicodeString &id)
Construct a TimeZone with a given ID.
static UResourceBundle * loadRule(const UResourceBundle *top, const UnicodeString &ruleid, UResourceBundle *oldbundle, UErrorCode &status)
Utility function.
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.
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.
TimeZone()
Default constructor.
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.
UBool operator!=(const TimeZone &that) const
Returns true if the two TimeZones are NOT equal; that is, if operator==() returns false.
Definition timezone.h:450
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
TimeZone(const TimeZone &source)
Copy constructor.
static StringEnumeration * createEnumeration(const char *country)
Returns an enumeration over time zone IDs associated with the given country.
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...
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.
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,...
UnicodeString & getID(UnicodeString &ID) const
Fills in "ID" with the TimeZone's ID.
Definition timezone.h:945
static const UnicodeString getEquivalentID(const UnicodeString &id, int32_t index)
Returns an ID in the equivalency group that includes the given ID.
static const TimeZone * getGMT(void)
The GMT (=UTC) time zone has a raw offset of zero and does not use daylight savings time.
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.
static void adoptDefault(TimeZone *zone)
Sets the default time zone (i.e., what's returned by createDefault()) to be the specified time zone.
static const UChar * getRegion(const UnicodeString &id, UErrorCode &status)
Returns the region code associated with the given zone, or NULL if the zone is not known.
virtual UBool inDaylightTime(UDate date, UErrorCode &status) const =0
Queries if the given date is in daylight savings time in this time zone.
static StringEnumeration * createEnumeration(int32_t rawOffset)
Returns an enumeration over time zone IDs with a given raw offset from GMT.
static TimeZone * createDefault(void)
Creates a new copy of the default TimeZone for this host.
UnicodeString & getDisplayName(UnicodeString &result) const
Returns a name of this time zone suitable for presentation to the user in the default locale.
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...
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.
virtual TimeZone * clone(void) const =0
Clones TimeZone objects polymorphically.
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.
static const char * getTZDataVersion(UErrorCode &status)
Returns the timezone data version currently used by ICU.
UObject is the common ICU "boilerplate" class.
Definition uobject.h:221
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:294
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C API: Calendar.
USystemTimeZoneType
System time zone type constants used by filtering zones in ucal_openTimeZoneIDEnumeration.
Definition ucal.h:530
int8_t UBool
The ICU boolean type.
Definition umachine.h:234
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
C API: Resource Bundle.
struct UResourceBundle UResourceBundle
Definition ures.h:57
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
double UDate
Date and Time data type.
Definition utypes.h:201
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129