• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 *******************************************************************************
3 * Copyright (C) 2007-2012, International Business Machines Corporation and    *
4 * others. All Rights Reserved.                                                *
5 *******************************************************************************
6 */
7 #ifndef ZONEMETA_H
8 #define ZONEMETA_H
9 
10 #include "unicode/utypes.h"
11 
12 #if !UCONFIG_NO_FORMATTING
13 
14 #include "unicode/unistr.h"
15 #include "hash.h"
16 
17 U_NAMESPACE_BEGIN
18 
19 typedef struct OlsonToMetaMappingEntry {
20     const UChar *mzid; // const because it's a reference to a resource bundle string.
21     UDate from;
22     UDate to;
23 } OlsonToMetaMappingEntry;
24 
25 class UVector;
26 class TimeZone;
27 
28 class U_I18N_API ZoneMeta {
29 public:
30     /**
31      * Return the canonical id for this tzid defined by CLDR, which might be the id itself.
32      * If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR is set in the status.
33      *
34      * Note: this internal API supports all known system IDs and "Etc/Unknown" (which is
35      * NOT a system ID).
36      */
37     static UnicodeString& U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UnicodeString &systemID, UErrorCode& status);
38 
39     /**
40      * Return the canonical id for this tzid defined by CLDR, which might be the id itself.
41      * This overload method returns a persistent const UChar*, which is guranteed to persist
42      * (a pointer to a resource).
43      */
44     static const UChar* U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status);
45 
46     /*
47      * Conveninent method returning CLDR canonical ID for the given time zone
48      */
49     static const UChar* U_EXPORT2 getCanonicalCLDRID(const TimeZone& tz);
50 
51     /**
52      * Return the canonical country code for this tzid.  If we have none, or if the time zone
53      * is not associated with a country, return null.
54      */
55     static UnicodeString& U_EXPORT2 getCanonicalCountry(const UnicodeString &tzid, UnicodeString &canonicalCountry);
56 
57     /**
58      * Return the country code if this is a 'single' time zone that can fallback to just
59      * the country, otherwise return empty string.  (Note, one must also check the locale data
60      * to see that there is a localization for the country in order to implement
61      * tr#35 appendix J step 5.)
62      */
63     static UnicodeString& U_EXPORT2 getSingleCountry(const UnicodeString &tzid, UnicodeString &country);
64 
65     /**
66      * Returns a CLDR metazone ID for the given Olson tzid and time.
67      */
68     static UnicodeString& U_EXPORT2 getMetazoneID(const UnicodeString &tzid, UDate date, UnicodeString &result);
69     /**
70      * Returns an Olson ID for the ginve metazone and region
71      */
72     static UnicodeString& U_EXPORT2 getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString &region, UnicodeString &result);
73 
74     static const UVector* U_EXPORT2 getMetazoneMappings(const UnicodeString &tzid);
75 
76     static const UVector* U_EXPORT2 getAvailableMetazoneIDs();
77 
78     /**
79      * Returns the pointer to the persistent time zone ID string, or NULL if the given tzid is not in the
80      * tz database. This method is useful when you maintain persistent zone IDs without duplication.
81      */
82     static const UChar* U_EXPORT2 findTimeZoneID(const UnicodeString& tzid);
83 
84     /**
85      * Returns the pointer to the persistent meta zone ID string, or NULL if the given mzid is not available.
86      * This method is useful when you maintain persistent meta zone IDs without duplication.
87      */
88     static const UChar* U_EXPORT2 findMetaZoneID(const UnicodeString& mzid);
89 
90     /**
91      * Creates a custom zone for the offset
92      * @param offset GMT offset in milliseconds
93      * @return A custom TimeZone for the offset with normalized time zone id
94      */
95     static TimeZone* createCustomTimeZone(int32_t offset);
96 
97 private:
98     ZoneMeta(); // Prevent construction.
99     static UVector* createMetazoneMappings(const UnicodeString &tzid);
100     static void initAvailableMetaZoneIDs();
101     static UnicodeString& formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id);
102 };
103 
104 U_NAMESPACE_END
105 
106 #endif /* #if !UCONFIG_NO_FORMATTING */
107 #endif // ZONEMETA_H
108