]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
4388f060 A |
3 | /* |
4 | ******************************************************************************* | |
f3c0d7a5 | 5 | * Copyright (C) 2011-2016, International Business Machines Corporation and |
57a6839d | 6 | * others. All Rights Reserved. |
4388f060 A |
7 | ******************************************************************************* |
8 | */ | |
9 | #ifndef __TZNAMES_H | |
10 | #define __TZNAMES_H | |
11 | ||
12 | /** | |
57a6839d | 13 | * \file |
4388f060 A |
14 | * \brief C++ API: TimeZoneNames |
15 | */ | |
16 | #include "unicode/utypes.h" | |
17 | ||
18 | #if !UCONFIG_NO_FORMATTING | |
4388f060 A |
19 | |
20 | #include "unicode/uloc.h" | |
21 | #include "unicode/unistr.h" | |
22 | ||
23 | U_CDECL_BEGIN | |
24 | ||
25 | /** | |
26 | * Constants for time zone display name types. | |
57a6839d | 27 | * @stable ICU 50 |
4388f060 A |
28 | */ |
29 | typedef enum UTimeZoneNameType { | |
30 | /** | |
31 | * Unknown display name type. | |
57a6839d | 32 | * @stable ICU 50 |
4388f060 A |
33 | */ |
34 | UTZNM_UNKNOWN = 0x00, | |
35 | /** | |
36 | * Long display name, such as "Eastern Time". | |
57a6839d | 37 | * @stable ICU 50 |
4388f060 A |
38 | */ |
39 | UTZNM_LONG_GENERIC = 0x01, | |
40 | /** | |
41 | * Long display name for standard time, such as "Eastern Standard Time". | |
57a6839d | 42 | * @stable ICU 50 |
4388f060 A |
43 | */ |
44 | UTZNM_LONG_STANDARD = 0x02, | |
45 | /** | |
46 | * Long display name for daylight saving time, such as "Eastern Daylight Time". | |
57a6839d | 47 | * @stable ICU 50 |
4388f060 A |
48 | */ |
49 | UTZNM_LONG_DAYLIGHT = 0x04, | |
50 | /** | |
51 | * Short display name, such as "ET". | |
57a6839d | 52 | * @stable ICU 50 |
4388f060 A |
53 | */ |
54 | UTZNM_SHORT_GENERIC = 0x08, | |
55 | /** | |
56 | * Short display name for standard time, such as "EST". | |
57a6839d | 57 | * @stable ICU 50 |
4388f060 A |
58 | */ |
59 | UTZNM_SHORT_STANDARD = 0x10, | |
60 | /** | |
61 | * Short display name for daylight saving time, such as "EDT". | |
57a6839d | 62 | * @stable ICU 50 |
51004dcb A |
63 | */ |
64 | UTZNM_SHORT_DAYLIGHT = 0x20, | |
51004dcb A |
65 | /** |
66 | * Exemplar location name, such as "Los Angeles". | |
57a6839d | 67 | * @stable ICU 51 |
4388f060 | 68 | */ |
51004dcb | 69 | UTZNM_EXEMPLAR_LOCATION = 0x40 |
4388f060 A |
70 | } UTimeZoneNameType; |
71 | ||
72 | U_CDECL_END | |
73 | ||
f3c0d7a5 | 74 | #if U_SHOW_CPLUSPLUS_API |
4388f060 A |
75 | U_NAMESPACE_BEGIN |
76 | ||
77 | class UVector; | |
78 | struct MatchInfo; | |
79 | ||
80 | /** | |
81 | * <code>TimeZoneNames</code> is an abstract class representing the time zone display name data model defined | |
82 | * by <a href="http://www.unicode.org/reports/tr35/">UTS#35 Unicode Locale Data Markup Language (LDML)</a>. | |
83 | * The model defines meta zone, which is used for storing a set of display names. A meta zone can be shared | |
84 | * by multiple time zones. Also a time zone may have multiple meta zone historic mappings. | |
85 | * <p> | |
86 | * For example, people in the United States refer the zone used by the east part of North America as "Eastern Time". | |
87 | * The tz database contains multiple time zones "America/New_York", "America/Detroit", "America/Montreal" and some | |
88 | * others that belong to "Eastern Time". However, assigning different display names to these time zones does not make | |
89 | * much sense for most of people. | |
90 | * <p> | |
91 | * In <a href="http://cldr.unicode.org/">CLDR</a> (which uses LDML for representing locale data), the display name | |
92 | * "Eastern Time" is stored as long generic display name of a meta zone identified by the ID "America_Eastern". | |
93 | * Then, there is another table maintaining the historic mapping to meta zones for each time zone. The time zones in | |
94 | * the above example ("America/New_York", "America/Detroit"...) are mapped to the meta zone "America_Eastern". | |
95 | * <p> | |
96 | * Sometimes, a time zone is mapped to a different time zone in the past. For example, "America/Indiana/Knox" | |
97 | * had been moving "Eastern Time" and "Central Time" back and forth. Therefore, it is necessary that time zone | |
98 | * to meta zones mapping data are stored by date range. | |
57a6839d | 99 | * |
4388f060 A |
100 | * <p><b>Note:</b> |
101 | * The methods in this class assume that time zone IDs are already canonicalized. For example, you may not get proper | |
102 | * result returned by a method with time zone ID "America/Indiana/Indianapolis", because it's not a canonical time zone | |
103 | * ID (the canonical time zone ID for the time zone is "America/Indianapolis". See | |
104 | * {@link TimeZone#getCanonicalID(const UnicodeString& id, UnicodeString& canonicalID, UErrorCode& status)} about ICU | |
105 | * canonical time zone IDs. | |
57a6839d | 106 | * |
4388f060 A |
107 | * <p> |
108 | * In CLDR, most of time zone display names except location names are provided through meta zones. But a time zone may | |
109 | * have a specific name that is not shared with other time zones. | |
110 | * | |
111 | * For example, time zone "Europe/London" has English long name for standard time "Greenwich Mean Time", which is also | |
112 | * shared with other time zones. However, the long name for daylight saving time is "British Summer Time", which is only | |
113 | * used for "Europe/London". | |
57a6839d | 114 | * |
4388f060 A |
115 | * <p> |
116 | * {@link #getTimeZoneDisplayName} is designed for accessing a name only used by a single time zone. | |
117 | * But is not necessarily mean that a subclass implementation use the same model with CLDR. A subclass implementation | |
118 | * may provide time zone names only through {@link #getTimeZoneDisplayName}, or only through {@link #getMetaZoneDisplayName}, | |
119 | * or both. | |
57a6839d | 120 | * |
51004dcb A |
121 | * <p> |
122 | * The default <code>TimeZoneNames</code> implementation returned by {@link #createInstance} | |
123 | * uses the locale data imported from CLDR. In CLDR, set of meta zone IDs and mappings between zone IDs and meta zone | |
124 | * IDs are shared by all locales. Therefore, the behavior of {@link #getAvailableMetaZoneIDs}, | |
125 | * {@link #getMetaZoneID}, and {@link #getReferenceZoneID} won't be changed no matter | |
126 | * what locale is used for getting an instance of <code>TimeZoneNames</code>. | |
127 | * | |
57a6839d | 128 | * @stable ICU 50 |
4388f060 A |
129 | */ |
130 | class U_I18N_API TimeZoneNames : public UObject { | |
131 | public: | |
132 | /** | |
133 | * Destructor. | |
57a6839d | 134 | * @stable ICU 50 |
4388f060 A |
135 | */ |
136 | virtual ~TimeZoneNames(); | |
137 | ||
138 | /** | |
f3c0d7a5 | 139 | * Return true if the given TimeZoneNames objects are semantically equal. |
4388f060 A |
140 | * @param other the object to be compared with. |
141 | * @return Return TRUE if the given Format objects are semantically equal. | |
57a6839d | 142 | * @stable ICU 50 |
4388f060 A |
143 | */ |
144 | virtual UBool operator==(const TimeZoneNames& other) const = 0; | |
145 | ||
146 | /** | |
147 | * Return true if the given TimeZoneNames objects are not semantically | |
148 | * equal. | |
149 | * @param other the object to be compared with. | |
150 | * @return Return TRUE if the given Format objects are not semantically equal. | |
57a6839d | 151 | * @stable ICU 50 |
4388f060 A |
152 | */ |
153 | UBool operator!=(const TimeZoneNames& other) const { return !operator==(other); } | |
154 | ||
155 | /** | |
156 | * Clone this object polymorphically. The caller is responsible | |
157 | * for deleting the result when done. | |
158 | * @return A copy of the object | |
57a6839d | 159 | * @stable ICU 50 |
4388f060 A |
160 | */ |
161 | virtual TimeZoneNames* clone() const = 0; | |
162 | ||
163 | /** | |
b331163b | 164 | * Returns an instance of <code>TimeZoneNames</code> for the specified locale. |
57a6839d | 165 | * |
4388f060 | 166 | * @param locale The locale. |
57a6839d | 167 | * @param status Receives the status. |
b331163b | 168 | * @return An instance of <code>TimeZoneNames</code> |
57a6839d | 169 | * @stable ICU 50 |
4388f060 A |
170 | */ |
171 | static TimeZoneNames* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status); | |
172 | ||
b331163b A |
173 | /** |
174 | * Returns an instance of <code>TimeZoneNames</code> containing only short specific | |
175 | * zone names (SHORT_STANDARD and SHORT_DAYLIGHT), | |
176 | * compatible with the IANA tz database's zone abbreviations (not localized). | |
177 | * <br> | |
178 | * Note: The input locale is used for resolving ambiguous names (e.g. "IST" is parsed | |
179 | * as Israel Standard Time for Israel, while it is parsed as India Standard Time for | |
180 | * all other regions). The zone names returned by this instance are not localized. | |
2ca993e8 | 181 | * @stable ICU 54 |
b331163b A |
182 | */ |
183 | static TimeZoneNames* U_EXPORT2 createTZDBInstance(const Locale& locale, UErrorCode& status); | |
b331163b | 184 | |
4388f060 A |
185 | /** |
186 | * Returns an enumeration of all available meta zone IDs. | |
57a6839d | 187 | * @param status Receives the status. |
4388f060 | 188 | * @return an enumeration object, owned by the caller. |
57a6839d | 189 | * @stable ICU 50 |
4388f060 A |
190 | */ |
191 | virtual StringEnumeration* getAvailableMetaZoneIDs(UErrorCode& status) const = 0; | |
192 | ||
193 | /** | |
194 | * Returns an enumeration of all available meta zone IDs used by the given time zone. | |
195 | * @param tzID The canoical tiem zone ID. | |
57a6839d | 196 | * @param status Receives the status. |
4388f060 | 197 | * @return an enumeration object, owned by the caller. |
57a6839d | 198 | * @stable ICU 50 |
4388f060 A |
199 | */ |
200 | virtual StringEnumeration* getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const = 0; | |
201 | ||
202 | /** | |
203 | * Returns the meta zone ID for the given canonical time zone ID at the given date. | |
204 | * @param tzID The canonical time zone ID. | |
205 | * @param date The date. | |
206 | * @param mzID Receives the meta zone ID for the given time zone ID at the given date. If the time zone does not have a | |
207 | * corresponding meta zone at the given date or the implementation does not support meta zones, "bogus" state | |
208 | * is set. | |
209 | * @return A reference to the result. | |
57a6839d | 210 | * @stable ICU 50 |
4388f060 A |
211 | */ |
212 | virtual UnicodeString& getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const = 0; | |
213 | ||
214 | /** | |
215 | * Returns the reference zone ID for the given meta zone ID for the region. | |
51004dcb A |
216 | * |
217 | * Note: Each meta zone must have a reference zone associated with a special region "001" (world). | |
218 | * Some meta zones may have region specific reference zone IDs other than the special region | |
219 | * "001". When a meta zone does not have any region specific reference zone IDs, this method | |
220 | * return the reference zone ID for the special region "001" (world). | |
221 | * | |
4388f060 A |
222 | * @param mzID The meta zone ID. |
223 | * @param region The region. | |
224 | * @param tzID Receives the reference zone ID ("golden zone" in the LDML specification) for the given time zone ID for the | |
225 | * region. If the meta zone is unknown or the implementation does not support meta zones, "bogus" state | |
226 | * is set. | |
227 | * @return A reference to the result. | |
57a6839d | 228 | * @stable ICU 50 |
4388f060 A |
229 | */ |
230 | virtual UnicodeString& getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const = 0; | |
231 | ||
232 | /** | |
233 | * Returns the display name of the meta zone. | |
234 | * @param mzID The meta zone ID. | |
235 | * @param type The display name type. See {@link #UTimeZoneNameType}. | |
236 | * @param name Receives the display name of the meta zone. When this object does not have a localized display name for the given | |
237 | * meta zone with the specified type or the implementation does not provide any display names associated | |
238 | * with meta zones, "bogus" state is set. | |
239 | * @return A reference to the result. | |
57a6839d | 240 | * @stable ICU 50 |
4388f060 A |
241 | */ |
242 | virtual UnicodeString& getMetaZoneDisplayName(const UnicodeString& mzID, UTimeZoneNameType type, UnicodeString& name) const = 0; | |
243 | ||
244 | /** | |
245 | * Returns the display name of the time zone. Unlike {@link #getDisplayName}, | |
246 | * this method does not get a name from a meta zone used by the time zone. | |
247 | * @param tzID The canonical time zone ID. | |
248 | * @param type The display name type. See {@link #UTimeZoneNameType}. | |
249 | * @param name Receives the display name for the time zone. When this object does not have a localized display name for the given | |
250 | * time zone with the specified type, "bogus" state is set. | |
251 | * @return A reference to the result. | |
57a6839d | 252 | * @stable ICU 50 |
4388f060 A |
253 | */ |
254 | virtual UnicodeString& getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const = 0; | |
255 | ||
256 | /** | |
257 | * Returns the exemplar location name for the given time zone. When this object does not have a localized location | |
258 | * name, the default implementation may still returns a programmatically generated name with the logic described | |
259 | * below. | |
260 | * <ol> | |
261 | * <li>Check if the ID contains "/". If not, return null. | |
262 | * <li>Check if the ID does not start with "Etc/" or "SystemV/". If it does, return null. | |
263 | * <li>Extract a substring after the last occurrence of "/". | |
264 | * <li>Replace "_" with " ". | |
265 | * </ol> | |
266 | * For example, "New York" is returned for the time zone ID "America/New_York" when this object does not have the | |
267 | * localized location name. | |
57a6839d | 268 | * |
4388f060 A |
269 | * @param tzID The canonical time zone ID |
270 | * @param name Receives the exemplar location name for the given time zone, or "bogus" state is set when a localized | |
271 | * location name is not available and the fallback logic described above cannot extract location from the ID. | |
272 | * @return A reference to the result. | |
57a6839d | 273 | * @stable ICU 50 |
4388f060 A |
274 | */ |
275 | virtual UnicodeString& getExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) const; | |
276 | ||
277 | /** | |
278 | * Returns the display name of the time zone at the given date. | |
279 | * <p> | |
280 | * <b>Note:</b> This method calls the subclass's {@link #getTimeZoneDisplayName} first. When the | |
281 | * result is bogus, this method calls {@link #getMetaZoneID} to get the meta zone ID mapped from the | |
282 | * time zone, then calls {@link #getMetaZoneDisplayName}. | |
57a6839d | 283 | * |
4388f060 A |
284 | * @param tzID The canonical time zone ID. |
285 | * @param type The display name type. See {@link #UTimeZoneNameType}. | |
286 | * @param date The date. | |
287 | * @param name Receives the display name for the time zone at the given date. When this object does not have a localized display | |
288 | * name for the time zone with the specified type and date, "bogus" state is set. | |
289 | * @return A reference to the result. | |
57a6839d | 290 | * @stable ICU 50 |
4388f060 A |
291 | */ |
292 | virtual UnicodeString& getDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UDate date, UnicodeString& name) const; | |
293 | ||
f3c0d7a5 A |
294 | /** |
295 | * @internal For specific users only until proposed publicly. | |
296 | * @deprecated This API is ICU internal only. | |
297 | */ | |
298 | virtual void loadAllDisplayNames(UErrorCode& status); | |
299 | ||
300 | /** | |
301 | * @internal For specific users only until proposed publicly. | |
302 | * @deprecated This API is ICU internal only. | |
303 | */ | |
304 | virtual void getDisplayNames(const UnicodeString& tzID, const UTimeZoneNameType types[], int32_t numTypes, UDate date, UnicodeString dest[], UErrorCode& status) const; | |
305 | ||
4388f060 A |
306 | /** |
307 | * <code>MatchInfoCollection</code> represents a collection of time zone name matches used by | |
308 | * {@link TimeZoneNames#find}. | |
51004dcb | 309 | * @internal |
4388f060 A |
310 | */ |
311 | class U_I18N_API MatchInfoCollection : public UMemory { | |
312 | public: | |
313 | /** | |
314 | * Constructor. | |
51004dcb | 315 | * @internal |
4388f060 A |
316 | */ |
317 | MatchInfoCollection(); | |
318 | /** | |
319 | * Destructor. | |
51004dcb | 320 | * @internal |
4388f060 A |
321 | */ |
322 | virtual ~MatchInfoCollection(); | |
323 | ||
51004dcb | 324 | #ifndef U_HIDE_INTERNAL_API |
4388f060 A |
325 | /** |
326 | * Adds a zone match. | |
327 | * @param nameType The name type. | |
328 | * @param matchLength The match length. | |
329 | * @param tzID The time zone ID. | |
330 | * @param status Receives the status | |
51004dcb | 331 | * @internal |
4388f060 A |
332 | */ |
333 | void addZone(UTimeZoneNameType nameType, int32_t matchLength, | |
334 | const UnicodeString& tzID, UErrorCode& status); | |
335 | ||
336 | /** | |
337 | * Adds a meata zone match. | |
338 | * @param nameType The name type. | |
339 | * @param matchLength The match length. | |
340 | * @param mzID The metazone ID. | |
341 | * @param status Receives the status | |
51004dcb | 342 | * @internal |
4388f060 A |
343 | */ |
344 | void addMetaZone(UTimeZoneNameType nameType, int32_t matchLength, | |
345 | const UnicodeString& mzID, UErrorCode& status); | |
346 | ||
347 | /** | |
348 | * Returns the number of entries available in this object. | |
349 | * @return The number of entries. | |
51004dcb | 350 | * @internal |
4388f060 A |
351 | */ |
352 | int32_t size() const; | |
353 | ||
354 | /** | |
355 | * Returns the time zone name type of a match at the specified index. | |
356 | * @param idx The index | |
357 | * @return The time zone name type. If the specified idx is out of range, | |
358 | * it returns UTZNM_UNKNOWN. | |
359 | * @see UTimeZoneNameType | |
51004dcb | 360 | * @internal |
4388f060 A |
361 | */ |
362 | UTimeZoneNameType getNameTypeAt(int32_t idx) const; | |
363 | ||
364 | /** | |
365 | * Returns the match length of a match at the specified index. | |
366 | * @param idx The index | |
4388f060 A |
367 | * @return The match length. If the specified idx is out of range, |
368 | * it returns 0. | |
51004dcb | 369 | * @internal |
4388f060 A |
370 | */ |
371 | int32_t getMatchLengthAt(int32_t idx) const; | |
372 | ||
373 | /** | |
374 | * Gets the zone ID of a match at the specified index. | |
375 | * @param idx The index | |
376 | * @param tzID Receives the zone ID. | |
377 | * @return TRUE if the zone ID was set to tzID. | |
51004dcb | 378 | * @internal |
4388f060 A |
379 | */ |
380 | UBool getTimeZoneIDAt(int32_t idx, UnicodeString& tzID) const; | |
381 | ||
382 | /** | |
383 | * Gets the metazone ID of a match at the specified index. | |
384 | * @param idx The index | |
385 | * @param mzID Receives the metazone ID | |
4388f060 | 386 | * @return TRUE if the meta zone ID was set to mzID. |
51004dcb | 387 | * @internal |
4388f060 A |
388 | */ |
389 | UBool getMetaZoneIDAt(int32_t idx, UnicodeString& mzID) const; | |
51004dcb | 390 | #endif /* U_HIDE_INTERNAL_API */ |
4388f060 A |
391 | |
392 | private: | |
393 | UVector* fMatches; // vector of MatchEntry | |
394 | ||
395 | UVector* matches(UErrorCode& status); | |
396 | }; | |
397 | ||
398 | /** | |
399 | * Finds time zone name prefix matches for the input text at the | |
400 | * given offset and returns a collection of the matches. | |
401 | * @param text The text. | |
402 | * @param start The starting offset within the text. | |
403 | * @param types The set of name types represented by bitwise flags of UTimeZoneNameType enums, | |
404 | * or UTZNM_UNKNOWN for all name types. | |
405 | * @param status Receives the status. | |
406 | * @return A collection of matches (owned by the caller), or NULL if no matches are found. | |
407 | * @see UTimeZoneNameType | |
408 | * @see MatchInfoCollection | |
51004dcb | 409 | * @internal |
4388f060 A |
410 | */ |
411 | virtual MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const = 0; | |
4388f060 A |
412 | }; |
413 | ||
414 | U_NAMESPACE_END | |
f3c0d7a5 | 415 | #endif // U_SHOW_CPLUSPLUS_API |
4388f060 | 416 | |
4388f060 A |
417 | #endif |
418 | #endif |