ICU 58.2 58.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

timezone.h
Go to the documentation of this file.
1 // Copyright (C) 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
46 U_NAMESPACE_BEGIN
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
194 static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
195 USystemTimeZoneType zoneType,
196 const char* region,
197 const int32_t* rawOffset,
198 UErrorCode& ec);
199
207 static StringEnumeration* U_EXPORT2 createEnumeration();
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
291 static TimeZone* U_EXPORT2 detectHostTimeZone();
292
305 static TimeZone* U_EXPORT2 createDefault(void);
306
320 static void U_EXPORT2 adoptDefault(TimeZone* zone);
321
322 #ifndef U_HIDE_SYSTEM_API
323
333 static void U_EXPORT2 setDefault(const TimeZone& zone);
334 #endif /* U_HIDE_SYSTEM_API */
335
342 static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
343
357 static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
358 UnicodeString& canonicalID, UErrorCode& status);
359
375 static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
376 UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
377
400 static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id,
401 UnicodeString& winid, UErrorCode& status);
402
429 static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
430 UnicodeString& id, UErrorCode& status);
431
441 virtual UBool operator==(const TimeZone& that) const;
442
452 UBool operator!=(const TimeZone& that) const {return !operator==(that);}
453
478 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
479 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
480
501 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
502 uint8_t dayOfWeek, int32_t milliseconds,
503 int32_t monthLength, UErrorCode& status) const = 0;
504
528 virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
529 int32_t& dstOffset, UErrorCode& ec) const;
530
538 virtual void setRawOffset(int32_t offsetMillis) = 0;
539
547 virtual int32_t getRawOffset(void) const = 0;
548
556 UnicodeString& getID(UnicodeString& ID) const;
557
571 void setID(const UnicodeString& ID);
572
577 enum EDisplayType {
582 SHORT = 1,
587 LONG,
592 SHORT_GENERIC,
597 LONG_GENERIC,
603 SHORT_GMT,
609 LONG_GMT,
615 SHORT_COMMONLY_USED,
621 GENERIC_LOCATION
622 };
623
635 UnicodeString& getDisplayName(UnicodeString& result) const;
636
650 UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
651
664 UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const;
665
680 UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
681
716 virtual UBool useDaylightTime(void) const = 0;
717
731 virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
732
741 virtual UBool hasSameRules(const TimeZone& other) const;
742
750 virtual TimeZone* clone(void) const = 0;
751
758 static UClassID U_EXPORT2 getStaticClassID(void);
759
771 virtual UClassID getDynamicClassID(void) const = 0;
772
788 virtual int32_t getDSTSavings() const;
789
807 static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
808 char *region, int32_t capacity, UErrorCode& status);
809
810 protected:
811
816 TimeZone();
817
823 TimeZone(const UnicodeString &id);
824
830 TimeZone(const TimeZone& source);
831
837 TimeZone& operator=(const TimeZone& right);
838
839 #ifndef U_HIDE_INTERNAL_API
840
849 static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
850 #endif /* U_HIDE_INTERNAL_API */
851
852 private:
853 friend class ZoneMeta;
854
855
856 static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
857
866 static const UChar* findID(const UnicodeString& id);
867
876 static const UChar* dereferOlsonLink(const UnicodeString& id);
877
884 static const UChar* getRegion(const UnicodeString& id);
885
886 public:
887 #ifndef U_HIDE_INTERNAL_API
888
896 static const UChar* getRegion(const UnicodeString& id, UErrorCode& status);
897 #endif /* U_HIDE_INTERNAL_API */
898
899 private:
910 static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
911 int32_t& minute, int32_t& second);
912
923 static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
924 UErrorCode& status);
925
935 static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
936 UBool negative, UnicodeString& id);
937
938 UnicodeString fID; // this time zone's ID
939
940 friend class TZEnumeration;
941 };
942
943
944 // -------------------------------------
945
946 inline UnicodeString&
947 TimeZone::getID(UnicodeString& ID) const
948 {
949 ID = fID;
950 return ID;
951 }
952
953 // -------------------------------------
954
955 inline void
956 TimeZone::setID(const UnicodeString& ID)
957 {
958 fID = ID;
959 }
960 U_NAMESPACE_END
961
962 #endif /* #if !UCONFIG_NO_FORMATTING */
963
964 #endif //_TIMEZONE
965 //eof
icu::TimeZone::setID
void setID(const UnicodeString &ID)
Sets the TimeZone&#39;s ID to the specified value.
Definition: timezone.h:956
ucal.h
C API: Calendar.
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
UDate
double UDate
Date and Time data type.
Definition: utypes.h:203
unistr.h
C++ API: Unicode String.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
icu::StringEnumeration
Base class for &#39;pure&#39; C++ implementations of uenum api.
Definition: strenum.h:57
icu::TimeZone::EDisplayType
EDisplayType
Enum for use with getDisplayName.
Definition: timezone.h:577
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:131
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:360
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::TimeZone::SHORT_GMT
Selector for short display name derived from time zone offset.
Definition: timezone.h:603
icu::TimeZone::getID
UnicodeString & getID(UnicodeString &ID) const
Fills in "ID" with the TimeZone&#39;s ID.
Definition: timezone.h:947
icu::TimeZone::SHORT_GENERIC
Selector for short generic display name.
Definition: timezone.h:592
icu::TimeZone::LONG_GENERIC
Selector for long generic display name.
Definition: timezone.h:597
icu::TimeZone::LONG
Selector for long display name.
Definition: timezone.h:587
uobject.h
C++ API: Common ICU base class UObject.
UChar
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:337
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
icu::TimeZone::SHORT_COMMONLY_USED
Selector for short display name derived from the time zone&#39;s fallback name.
Definition: timezone.h:615
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:452
USystemTimeZoneType
USystemTimeZoneType
System time zone type constants used by filtering zones in ucal_openTimeZoneIDEnumeration.
Definition: ucal.h:534
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
UResourceBundle
struct UResourceBundle UResourceBundle
Definition: ures.h:59
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::TimeZone::LONG_GMT
Selector for long display name derived from time zone offset.
Definition: timezone.h:609
ures.h
C API: Resource Bundle.
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:259
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187