ICU 69.1 69.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
34#if U_SHOW_CPLUSPLUS_API
35
41#if !UCONFIG_NO_FORMATTING
42
43#include "unicode/uobject.h"
44#include "unicode/unistr.h"
45#include "unicode/ures.h"
46#include "unicode/ucal.h"
47
48U_NAMESPACE_BEGIN
49
50class StringEnumeration;
51
134public:
138 virtual ~TimeZone();
139
153
166 static const TimeZone* U_EXPORT2 getGMT(void);
167
180
198 const char* region,
199 const int32_t* rawOffset,
200 UErrorCode& ec);
201
210
229
240 static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
241
257
278 int32_t index);
279
304
319
320#ifndef U_HIDE_INTERNAL_API
331#endif /* U_HIDE_INTERNAL_API */
332
343
344#ifndef U_HIDE_SYSTEM_API
353 static void U_EXPORT2 setDefault(const TimeZone& zone);
354#endif /* U_HIDE_SYSTEM_API */
355
363
379
397
422
449 static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
451
461 virtual UBool operator==(const TimeZone& that) const;
462
472 UBool operator!=(const TimeZone& that) const {return !operator==(that);}
473
500
523 int32_t monthLength, UErrorCode& status) const = 0;
524
548 virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
549 int32_t& dstOffset, UErrorCode& ec) const;
550
559
567 virtual int32_t getRawOffset(void) const = 0;
568
576 UnicodeString& getID(UnicodeString& ID) const;
577
591 void setID(const UnicodeString& ID);
592
643
656
671
685
701
736 virtual UBool useDaylightTime(void) const = 0;
737
738#ifndef U_FORCE_HIDE_DEPRECATED_API
753#endif // U_FORCE_HIDE_DEPRECATED_API
754
763 virtual UBool hasSameRules(const TimeZone& other) const;
764
772 virtual TimeZone* clone() const = 0;
773
781
793 virtual UClassID getDynamicClassID(void) const = 0;
794
810 virtual int32_t getDSTSavings() const;
811
830 char *region, int32_t capacity, UErrorCode& status);
831
832protected:
833
839
846
852 TimeZone(const TimeZone& source);
853
860
861#ifndef U_HIDE_INTERNAL_API
872#endif /* U_HIDE_INTERNAL_API */
873
874private:
875 friend class ZoneMeta;
876
877
878 static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
879
888 static const char16_t* findID(const UnicodeString& id);
889
898 static const char16_t* dereferOlsonLink(const UnicodeString& id);
899
906 static const char16_t* getRegion(const UnicodeString& id);
907
908 public:
909#ifndef U_HIDE_INTERNAL_API
918 static const char16_t* getRegion(const UnicodeString& id, UErrorCode& status);
919#endif /* U_HIDE_INTERNAL_API */
920
921 private:
932 static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
934
945 static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
947
957 static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
959
960 UnicodeString fID; // this time zone's ID
961
962 friend class TZEnumeration;
963};
964
965
966// -------------------------------------
967
968inline UnicodeString&
969TimeZone::getID(UnicodeString& ID) const
970{
971 ID = fID;
972 return ID;
973}
974
975// -------------------------------------
976
977inline void
978TimeZone::setID(const UnicodeString& ID)
979{
980 fID = ID;
981}
983
984#endif /* #if !UCONFIG_NO_FORMATTING */
985
986#endif /* U_SHOW_CPLUSPLUS_API */
987
988#endif //_TIMEZONE
989//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:195
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:61
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:133
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
static UResourceBundle * loadRule(const UResourceBundle *top, const UnicodeString &ruleid, UResourceBundle *oldbundle, UErrorCode &status)
Utility function.
EDisplayType
Enum for use with getDisplayName.
Definition timezone.h:597
@ SHORT_COMMONLY_USED
Selector for short display name derived from the time zone's fallback name.
Definition timezone.h:635
@ LONG_GMT
Selector for long display name derived from time zone offset.
Definition timezone.h:629
@ SHORT_GENERIC
Selector for short generic display name.
Definition timezone.h:612
@ LONG
Selector for long display name.
Definition timezone.h:607
@ SHORT_GMT
Selector for short display name derived from time zone offset.
Definition timezone.h:623
@ LONG_GENERIC
Selector for long generic display name.
Definition timezone.h:617
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.
UnicodeString & getDisplayName(UBool inDaylight, 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.
static UClassID getStaticClassID(void)
Return the class ID for this class.
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 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,...
static void setDefault(const TimeZone &zone)
Same as adoptDefault(), except that the TimeZone object passed in is NOT adopted; the caller remains ...
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...
virtual UBool operator==(const TimeZone &that) const
Returns true if the two TimeZones are equal.
TimeZone(const TimeZone &source)
Copy constructor.
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...
static StringEnumeration * createEnumeration(int32_t rawOffset)
Returns an enumeration over time zone IDs with a given raw offset from GMT.
static StringEnumeration * createEnumeration()
Returns an enumeration over all recognized time zone IDs.
static const TimeZone * getGMT(void)
The GMT (=UTC) time zone has a raw offset of zero and does not use daylight savings time.
static TimeZone * detectHostTimeZone()
Creates an instance of TimeZone detected from the current host system configuration.
TimeZone(const UnicodeString &id)
Construct a TimeZone with a given ID.
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.
virtual TimeZone * clone() const =0
Clones TimeZone objects polymorphically.
static UnicodeString & getWindowsID(const UnicodeString &id, UnicodeString &winid, UErrorCode &status)
Converts a system time zone ID to an equivalent Windows time zone ID.
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...
UBool operator!=(const TimeZone &that) const
Returns true if the two TimeZones are NOT equal; that is, if operator==() returns false.
Definition timezone.h:472
virtual UBool useDaylightTime(void) const =0
Queries if this time zone uses daylight savings time.
virtual UBool hasSameRules(const TimeZone &other) const
Returns true if this zone has the same rule and offset as another zone.
static int32_t countEquivalentIDs(const UnicodeString &id)
Returns the number of IDs in the equivalency group that includes the given ID.
static void adoptDefault(TimeZone *zone)
Sets the default time zone (i.e., what's returned by createDefault()) to be the specified time zone.
UnicodeString & getDisplayName(UnicodeString &result) const
Returns a name of this time zone suitable for presentation to the user in the default locale.
TimeZone()
Default constructor.
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.
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.
TimeZone & operator=(const TimeZone &right)
Default assignment operator.
UnicodeString & getDisplayName(UBool inDaylight, EDisplayType style, UnicodeString &result) const
Returns a name of this time zone suitable for presentation to the user in the default locale.
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.
static TimeZone * createDefault(void)
Creates a new copy of the default TimeZone for this host.
static const UnicodeString getEquivalentID(const UnicodeString &id, int32_t index)
Returns an ID in the equivalency group that includes the given ID.
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.
virtual UBool inDaylightTime(UDate date, UErrorCode &status) const =0
Queries if the given date is in daylight savings time in this time zone.
static TimeZone * createTimeZone(const UnicodeString &ID)
Creates a TimeZone for the given ID.
virtual ~TimeZone()
static TimeZone * forLocaleOrDefault(const Locale &locale)
If the locale contains the timezone keyword, creates a copy of that TimeZone.
virtual int32_t getDSTSavings() const
Returns the amount of time to be added to local standard time to get local wall clock time.
static StringEnumeration * createEnumeration(const char *country)
Returns an enumeration over time zone IDs associated with the given country.
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.
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:223
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
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:553
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
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:62
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:415
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:301
double UDate
Date and Time data type.
Definition utypes.h:203