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
48 U_NAMESPACE_BEGIN
49
50 class StringEnumeration;
51
133 class U_I18N_API TimeZone : public UObject {
134 public:
138 virtual ~TimeZone();
139
152 static const TimeZone& U_EXPORT2 getUnknown();
153
166 static const TimeZone* U_EXPORT2 getGMT(void);
167
179 static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
180
196 static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
197 USystemTimeZoneType zoneType,
198 const char* region,
199 const int32_t* rawOffset,
200 UErrorCode& ec);
201
209 static StringEnumeration* U_EXPORT2 createEnumeration();
210
228 static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
229
240 static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
241
256 static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
257
277 static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
278 int32_t index);
279
303 static TimeZone* U_EXPORT2 detectHostTimeZone();
304
318 static TimeZone* U_EXPORT2 createDefault(void);
319
320 #ifndef U_HIDE_INTERNAL_API
321
330 static TimeZone* U_EXPORT2 forLocaleOrDefault(const Locale& locale);
331 #endif /* U_HIDE_INTERNAL_API */
332
342 static void U_EXPORT2 adoptDefault(TimeZone* zone);
343
344 #ifndef U_HIDE_SYSTEM_API
345
353 static void U_EXPORT2 setDefault(const TimeZone& zone);
354 #endif /* U_HIDE_SYSTEM_API */
355
362 static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
363
377 static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
378 UnicodeString& canonicalID, UErrorCode& status);
379
395 static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
396 UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
397
420 static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id,
421 UnicodeString& winid, UErrorCode& status);
422
449 static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
450 UnicodeString& id, UErrorCode& status);
451
461 virtual UBool operator==(const TimeZone& that) const;
462
472 UBool operator!=(const TimeZone& that) const {return !operator==(that);}
473
498 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
499 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
500
521 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
522 uint8_t dayOfWeek, int32_t milliseconds,
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
558 virtual void setRawOffset(int32_t offsetMillis) = 0;
559
567 virtual int32_t getRawOffset(void) const = 0;
568
576 UnicodeString& getID(UnicodeString& ID) const;
577
591 void setID(const UnicodeString& ID);
592
597 enum EDisplayType {
602 SHORT = 1,
607 LONG,
612 SHORT_GENERIC,
617 LONG_GENERIC,
623 SHORT_GMT,
629 LONG_GMT,
635 SHORT_COMMONLY_USED,
641 GENERIC_LOCATION
642 };
643
655 UnicodeString& getDisplayName(UnicodeString& result) const;
656
670 UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
671
684 UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, UnicodeString& result) const;
685
700 UnicodeString& getDisplayName(UBool inDaylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
701
736 virtual UBool useDaylightTime(void) const = 0;
737
738 #ifndef U_FORCE_HIDE_DEPRECATED_API
739
752 virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
753 #endif // U_FORCE_HIDE_DEPRECATED_API
754
763 virtual UBool hasSameRules(const TimeZone& other) const;
764
772 virtual TimeZone* clone() const = 0;
773
780 static UClassID U_EXPORT2 getStaticClassID(void);
781
793 virtual UClassID getDynamicClassID(void) const = 0;
794
810 virtual int32_t getDSTSavings() const;
811
829 static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
830 char *region, int32_t capacity, UErrorCode& status);
831
832 protected:
833
838 TimeZone();
839
845 TimeZone(const UnicodeString &id);
846
852 TimeZone(const TimeZone& source);
853
859 TimeZone& operator=(const TimeZone& right);
860
861 #ifndef U_HIDE_INTERNAL_API
862
871 static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
872 #endif /* U_HIDE_INTERNAL_API */
873
874 private:
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
910
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,
933 int32_t& minute, int32_t& second);
934
945 static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
946 UErrorCode& status);
947
957 static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
958 UBool negative, UnicodeString& id);
959
960 UnicodeString fID; // this time zone's ID
961
962 friend class TZEnumeration;
963 };
964
965
966 // -------------------------------------
967
968 inline UnicodeString&
969 TimeZone::getID(UnicodeString& ID) const
970 {
971 ID = fID;
972 return ID;
973 }
974
975 // -------------------------------------
976
977 inline void
978 TimeZone::setID(const UnicodeString& ID)
979 {
980 fID = ID;
981 }
982 U_NAMESPACE_END
983
984 #endif /* #if !UCONFIG_NO_FORMATTING */
985
986 #endif /* U_SHOW_CPLUSPLUS_API */
987
988 #endif //_TIMEZONE
989 //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:635
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
icu::TimeZone::SHORT_GENERIC
@ SHORT_GENERIC
Selector for short generic display name.
Definition: timezone.h:612
UResourceBundle
struct UResourceBundle UResourceBundle
Definition: ures.h:62
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:597
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
ures.h
C API: Resource Bundle.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
ucal.h
C API: Calendar.
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:629
icu::TimeZone::SHORT_GMT
@ SHORT_GMT
Selector for short display name derived from time zone offset.
Definition: timezone.h:623
icu::TimeZone::LONG_GENERIC
@ LONG_GENERIC
Selector for long generic display name.
Definition: timezone.h:617
uobject.h
C++ API: Common ICU base class UObject.
icu::TimeZone::LONG
@ LONG
Selector for long display name.
Definition: timezone.h:607
USystemTimeZoneType
USystemTimeZoneType
System time zone type constants used by filtering zones in ucal_openTimeZoneIDEnumeration.
Definition: ucal.h:553
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:472
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
unistr.h
C++ API: Unicode String.