Debian Codegraph @

intl/icu/source/i18n/zonemeta.h

raw
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2007-2013, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
8 */
9 #ifndef ZONEMETA_H
10 #define ZONEMETA_H
11
12 #include "unicode/utypes.h"
13
14 #if !UCONFIG_NO_FORMATTING
15
16 #include "unicode/unistr.h"
17 #include "hash.h"
18
19 U_NAMESPACE_BEGIN
20
21 struct OlsonToMetaMappingEntry : public UMemory {
22 const char16_t *mzid; // const because it's a reference to a resource bundle string.
23 UDate from;
24 UDate to;
25 };
26
27 class UVector;
28 class TimeZone;
29
30 class U_I18N_API ZoneMeta {
31 public:
32 /**
33 * Return the canonical id for this tzid defined by CLDR, which might be the id itself.
34 * If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR is set in the status.
35 *
36 * Note: this internal API supports all known system IDs and "Etc/Unknown" (which is
37 * NOT a system ID).
38 */
39 static UnicodeString& U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UnicodeString &systemID, UErrorCode& status);
40
41 /**
42 * Return the canonical id for this tzid defined by CLDR, which might be the id itself.
43 * This overload method returns a persistent const char16_t*, which is guaranteed to persist
44 * (a pointer to a resource). If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR
45 * is set in the status.
46 * @param tzid Zone ID
47 * @param status Receives the status
48 * @return The canonical ID for the input time zone ID
49 */
50 static const char16_t* U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status);
51
52 /*
53 * Convenient method returning CLDR canonical ID for the given time zone
54 */
55 static const char16_t* U_EXPORT2 getCanonicalCLDRID(const TimeZone& tz);
56
57 /**
58 * Returns primary IANA zone ID for the input zone ID, which might be the id itself.
59 * If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR is set in the status.
60 *
61 * @param tzid Zone ID
62 * @param ianaID Output IANA ID
63 * @param status Receives the status
64 * @return A primary IANA zone ID equivalent to the input zone ID.
65 */
66 static UnicodeString& U_EXPORT2 getIanaID(const UnicodeString& tzid, UnicodeString& ianaID, UErrorCode& status);
67
68 /**
69 * Return the canonical country code for this tzid. If we have none, or if the time zone
70 * is not associated with a country, return bogus string.
71 * @param tzid Zone ID
72 * @param country [output] Country code
73 * @param isPrimary [output] true if the zone is the primary zone for the country
74 * @return A reference to the result country
75 */
76 static UnicodeString& U_EXPORT2 getCanonicalCountry(const UnicodeString &tzid, UnicodeString &country, UBool *isPrimary = nullptr);
77
78 /**
79 * Returns a CLDR metazone ID for the given Olson tzid and time.
80 */
81 static UnicodeString& U_EXPORT2 getMetazoneID(const UnicodeString &tzid, UDate date, UnicodeString &result);
82 /**
83 * Returns an Olson ID for the ginve metazone and region
84 */
85 static UnicodeString& U_EXPORT2 getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString &region, UnicodeString &result);
86
87 static const UVector* U_EXPORT2 getMetazoneMappings(const UnicodeString &tzid);
88
89 static const UVector* U_EXPORT2 getAvailableMetazoneIDs();
90
91 /**
92 * Returns the pointer to the persistent time zone ID string, or nullptr if the given tzid is not in the
93 * tz database. This method is useful when you maintain persistent zone IDs without duplication.
94 */
95 static const char16_t* U_EXPORT2 findTimeZoneID(const UnicodeString& tzid);
96
97 /**
98 * Returns the pointer to the persistent meta zone ID string, or nullptr if the given mzid is not available.
99 * This method is useful when you maintain persistent meta zone IDs without duplication.
100 */
101 static const char16_t* U_EXPORT2 findMetaZoneID(const UnicodeString& mzid);
102
103 /**
104 * Creates a custom zone for the offset
105 * @param offset GMT offset in milliseconds
106 * @return A custom TimeZone for the offset with normalized time zone id
107 */
108 static TimeZone* createCustomTimeZone(int32_t offset);
109
110 /**
111 * Returns the time zone's short ID (null terminated) for the zone.
112 * For example, "uslax" for zone "America/Los_Angeles".
113 * @param tz the time zone
114 * @return the short ID of the time zone, or null if the short ID is not available.
115 */
116 static const char16_t* U_EXPORT2 getShortID(const TimeZone& tz);
117
118 /**
119 * Returns the time zone's short ID (null terminated) for the zone ID.
120 * For example, "uslax" for zone ID "America/Los_Angeles".
121 * @param tz the time zone ID
122 * @return the short ID of the time zone ID, or null if the short ID is not available.
123 */
124 static const char16_t* U_EXPORT2 getShortID(const UnicodeString& id);
125
126 private:
127 ZoneMeta() = delete; // Prevent construction.
128 static UVector* createMetazoneMappings(const UnicodeString &tzid);
129 static UnicodeString& formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id);
130 static const char16_t* getShortIDFromCanonical(const char16_t* canonicalID);
131 };
132
133 U_NAMESPACE_END
134
135 #endif /* #if !UCONFIG_NO_FORMATTING */
136 #endif // ZONEMETA_H