ICU 50.2 50.2
timezone.h
Go to the documentation of this file.
1/*************************************************************************
2* Copyright (c) 1997-2012, 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
36
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
136#ifndef U_HIDE_DRAFT_API
149 static const TimeZone& U_EXPORT2 getUnknown();
150#endif /* U_HIDE_DRAFT_API */
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
290 static TimeZone* U_EXPORT2 createDefault(void);
291
301 static void U_EXPORT2 adoptDefault(TimeZone* zone);
302
303#ifndef U_HIDE_SYSTEM_API
312 static void U_EXPORT2 setDefault(const TimeZone& zone);
313#endif /* U_HIDE_SYSTEM_API */
314
321 static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
322
336 static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
337 UnicodeString& canonicalID, UErrorCode& status);
338
354 static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
355 UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
356
366 virtual UBool operator==(const TimeZone& that) const;
367
377 UBool operator!=(const TimeZone& that) const {return !operator==(that);}
378
403 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
404 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
405
426 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
427 uint8_t dayOfWeek, int32_t milliseconds,
428 int32_t monthLength, UErrorCode& status) const = 0;
429
453 virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
454 int32_t& dstOffset, UErrorCode& ec) const;
455
463 virtual void setRawOffset(int32_t offsetMillis) = 0;
464
472 virtual int32_t getRawOffset(void) const = 0;
473
482
496 void setID(const UnicodeString& ID);
497
548
561
575 UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
576
590
605 UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
606
641 virtual UBool useDaylightTime(void) const = 0;
642
656 virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
657
666 virtual UBool hasSameRules(const TimeZone& other) const;
667
675 virtual TimeZone* clone(void) const = 0;
676
683 static UClassID U_EXPORT2 getStaticClassID(void);
684
696 virtual UClassID getDynamicClassID(void) const = 0;
697
713 virtual int32_t getDSTSavings() const;
714
732 static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
733 char *region, int32_t capacity, UErrorCode& status);
734
735protected:
736
742
749
755 TimeZone(const TimeZone& source);
756
763
764#ifndef U_HIDE_INTERNAL_API
774 static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
775#endif /* U_HIDE_INTERNAL_API */
776
777private:
778 friend class ZoneMeta;
779
780
781 static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
782
791 static const UChar* findID(const UnicodeString& id);
792
801 static const UChar* dereferOlsonLink(const UnicodeString& id);
802
809 static const UChar* getRegion(const UnicodeString& id);
810
818 static const UChar* getRegion(const UnicodeString& id, UErrorCode& status);
819
830 static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
831 int32_t& minute, int32_t& second);
832
843 static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
844 UErrorCode& status);
845
855 static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
856 UBool negative, UnicodeString& id);
857
863 static void initDefault(void);
864
865 // See source file for documentation
873 static TimeZone* createSystemTimeZone(const UnicodeString& name);
874 static TimeZone* createSystemTimeZone(const UnicodeString& name, UErrorCode& ec);
875
876 UnicodeString fID; // this time zone's ID
877
878 friend class TZEnumeration;
879};
880
881
882// -------------------------------------
883
884inline UnicodeString&
886{
887 ID = fID;
888 return ID;
889}
890
891// -------------------------------------
892
893inline void
895{
896 fID = ID;
897}
899
900#endif /* #if !UCONFIG_NO_FORMATTING */
901
902#endif //_TIMEZONE
903//eof
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:55
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:502
@ LONG
Selector for long display name.
Definition timezone.h:512
@ SHORT_COMMONLY_USED
Selector for short display name derived from the time zone's fallback name.
Definition timezone.h:540
@ SHORT
Selector for short display name.
Definition timezone.h:507
@ SHORT_GENERIC
Selector for short generic display name.
Definition timezone.h:517
@ GENERIC_LOCATION
Selector for long display name derived from the time zone's fallback name.
Definition timezone.h:546
@ LONG_GMT
Selector for long display name derived from time zone offset.
Definition timezone.h:534
@ LONG_GENERIC
Selector for long generic display name.
Definition timezone.h:522
@ SHORT_GMT
Selector for short display name derived from time zone offset.
Definition timezone.h:528
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:894
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 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.
UBool operator!=(const TimeZone &that) const
Returns true if the two TimeZones are NOT equal; that is, if operator==() returns false.
Definition timezone.h:377
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:885
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.
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:229
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
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:200
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition umachine.h:278
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
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