2 *******************************************************************************
3 * Copyright (C) 1997-2012, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
9 * Modification History:
11 * Date Name Description
12 * 12/05/96 clhuang Creation.
13 * 04/21/97 aliu General clean-up and bug fixing.
14 * 05/08/97 aliu Fixed Hashtable code per code review.
15 * 07/09/97 helena Changed createInstance to createDefault.
16 * 07/29/97 aliu Updated with all-new list of 96 UNIX-derived
17 * TimeZones. Changed mechanism to load from static
18 * array rather than resource bundle.
19 * 07/07/1998 srl Bugfixes from the Java side: UTC GMT CAT NST
20 * Added getDisplayName API
21 * going to add custom parsing.
24 * - should getDisplayName cache something?
25 * - should custom time zones be cached? [probably]
26 * 08/10/98 stephen Brought getDisplayName() API in-line w/ conventions
27 * 08/19/98 stephen Changed createTimeZone() to never return 0
28 * 09/02/98 stephen Added getOffset(monthLen) and hasSameRules()
29 * 09/15/98 stephen Added getStaticClassID()
30 * 02/22/99 stephen Removed character literals for EBCDIC safety
31 * 05/04/99 stephen Changed initDefault() for Mutex issues
32 * 07/12/99 helena HPUX 11 CC Port.
33 * 12/03/99 aliu Moved data out of static table into icudata.dll.
34 * Substantial rewrite of zone lookup, default zone, and
35 * available IDs code. Misc. cleanup.
36 *********************************************************************************/
38 #include <typeinfo> // for 'typeid' to work
40 #include "unicode/utypes.h"
41 #include "unicode/ustring.h"
46 # include "uresimp.h" // for debugging
48 static void debug_tz_loc(const char *f
, int32_t l
)
50 fprintf(stderr
, "%s:%d: ", f
, l
);
53 static void debug_tz_msg(const char *pat
, ...)
57 vfprintf(stderr
, pat
, ap
);
60 static char gStrBuf
[256];
61 #define U_DEBUG_TZ_STR(x) u_austrncpy(gStrBuf,x,sizeof(gStrBuf)-1)
62 // must use double parens, i.e.: U_DEBUG_TZ_MSG(("four is: %d",4));
63 #define U_DEBUG_TZ_MSG(x) {debug_tz_loc(__FILE__,__LINE__);debug_tz_msg x;}
65 #define U_DEBUG_TZ_MSG(x)
68 #if !UCONFIG_NO_FORMATTING
70 #include "unicode/simpletz.h"
71 #include "unicode/calendar.h"
72 #include "unicode/gregocal.h"
73 #include "unicode/ures.h"
74 #include "unicode/tzfmt.h"
75 #include "unicode/numfmt.h"
77 #include "uresimp.h" // struct UResourceBundle
80 #include "unicode/udata.h"
84 #include "unicode/strenum.h"
88 #define kZONEINFO "zoneinfo64"
89 #define kREGIONS "Regions"
90 #define kZONES "Zones"
91 #define kRULES "Rules"
92 #define kNAMES "Names"
93 #define kTZVERSION "TZVersion"
94 #define kLINKS "links"
95 #define kMAX_CUSTOM_HOUR 23
96 #define kMAX_CUSTOM_MIN 59
97 #define kMAX_CUSTOM_SEC 59
100 #define ZERO_DIGIT 0x0030
103 // Static data and constants
105 static const UChar WORLD
[] = {0x30, 0x30, 0x31, 0x00}; /* "001" */
107 static const UChar GMT_ID
[] = {0x47, 0x4D, 0x54, 0x00}; /* "GMT" */
108 static const UChar UNKNOWN_ZONE_ID
[] = {0x45, 0x74, 0x63, 0x2F, 0x55, 0x6E, 0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x00}; /* "Etc/Unknown" */
109 static const UChar Z_STR
[] = {0x7A, 0x00}; /* "z" */
110 static const UChar ZZZZ_STR
[] = {0x7A, 0x7A, 0x7A, 0x7A, 0x00}; /* "zzzz" */
111 static const UChar Z_UC_STR
[] = {0x5A, 0x00}; /* "Z" */
112 static const UChar ZZZZ_UC_STR
[] = {0x5A, 0x5A, 0x5A, 0x5A, 0x00}; /* "ZZZZ" */
113 static const UChar V_STR
[] = {0x76, 0x00}; /* "v" */
114 static const UChar VVVV_STR
[] = {0x76, 0x76, 0x76, 0x76, 0x00}; /* "vvvv" */
115 static const UChar V_UC_STR
[] = {0x56, 0x00}; /* "V" */
116 static const UChar VVVV_UC_STR
[] = {0x56, 0x56, 0x56, 0x56, 0x00}; /* "VVVV" */
117 static const int32_t GMT_ID_LENGTH
= 3;
118 static const int32_t UNKNOWN_ZONE_ID_LENGTH
= 11;
121 static UMTX TZSET_LOCK
;
122 static icu::TimeZone
* DEFAULT_ZONE
= NULL
;
123 static icu::TimeZone
* _GMT
= NULL
;
124 static icu::TimeZone
* _UNKNOWN_ZONE
= NULL
;
126 static char TZDATA_VERSION
[16];
127 static UBool TZDataVersionInitialized
= FALSE
;
129 static int32_t* MAP_SYSTEM_ZONES
= NULL
;
130 static int32_t* MAP_CANONICAL_SYSTEM_ZONES
= NULL
;
131 static int32_t* MAP_CANONICAL_SYSTEM_LOCATION_ZONES
= NULL
;
133 static int32_t LEN_SYSTEM_ZONES
= 0;
134 static int32_t LEN_CANONICAL_SYSTEM_ZONES
= 0;
135 static int32_t LEN_CANONICAL_SYSTEM_LOCATION_ZONES
= 0;
138 static UBool U_CALLCONV
timeZone_cleanup(void)
146 delete _UNKNOWN_ZONE
;
147 _UNKNOWN_ZONE
= NULL
;
149 uprv_memset(TZDATA_VERSION
, 0, sizeof(TZDATA_VERSION
));
150 TZDataVersionInitialized
= FALSE
;
152 LEN_SYSTEM_ZONES
= 0;
153 uprv_free(MAP_SYSTEM_ZONES
);
154 MAP_SYSTEM_ZONES
= 0;
156 LEN_CANONICAL_SYSTEM_ZONES
= 0;
157 uprv_free(MAP_CANONICAL_SYSTEM_ZONES
);
158 MAP_CANONICAL_SYSTEM_ZONES
= 0;
160 LEN_CANONICAL_SYSTEM_LOCATION_ZONES
= 0;
161 uprv_free(MAP_CANONICAL_SYSTEM_LOCATION_ZONES
);
162 MAP_CANONICAL_SYSTEM_LOCATION_ZONES
= 0;
169 umtx_destroy(&TZSET_LOCK
);
179 static int32_t findInStringArray(UResourceBundle
* array
, const UnicodeString
& id
, UErrorCode
&status
)
186 int32_t limit
= ures_getSize(array
);
188 int32_t lastMid
= INT32_MAX
;
189 if(U_FAILURE(status
) || (limit
< 1)) {
192 U_DEBUG_TZ_MSG(("fisa: Looking for %s, between %d and %d\n", U_DEBUG_TZ_STR(UnicodeString(id
).getTerminatedBuffer()), start
, limit
));
195 mid
= (int32_t)((start
+ limit
) / 2);
196 if (lastMid
== mid
) { /* Have we moved? */
197 break; /* We haven't moved, and it wasn't found. */
200 u
= ures_getStringByIndex(array
, mid
, &len
, &status
);
201 if (U_FAILURE(status
)) {
204 U_DEBUG_TZ_MSG(("tz: compare to %s, %d .. [%d] .. %d\n", U_DEBUG_TZ_STR(u
), start
, mid
, limit
));
205 copy
.setTo(TRUE
, u
, len
);
206 int r
= id
.compare(copy
);
208 U_DEBUG_TZ_MSG(("fisa: found at %d\n", mid
));
216 U_DEBUG_TZ_MSG(("fisa: not found\n"));
221 * Fetch a specific zone by name. Replaces the getByKey call.
222 * @param top Top timezone resource
223 * @param id Time zone ID
224 * @param oldbundle Bundle for reuse (or NULL). see 'ures_open()'
225 * @return the zone's bundle if found, or undefined if error. Reuses oldbundle.
227 static UResourceBundle
* getZoneByName(const UResourceBundle
* top
, const UnicodeString
& id
, UResourceBundle
*oldbundle
, UErrorCode
& status
) {
228 // load the Rules object
229 UResourceBundle
*tmp
= ures_getByKey(top
, kNAMES
, NULL
, &status
);
231 // search for the string
232 int32_t idx
= findInStringArray(tmp
, id
, status
);
234 if((idx
== -1) && U_SUCCESS(status
)) {
236 status
= U_MISSING_RESOURCE_ERROR
;
237 //ures_close(oldbundle);
240 U_DEBUG_TZ_MSG(("gzbn: oldbundle= size %d, type %d, %s\n", ures_getSize(tmp
), ures_getType(tmp
), u_errorName(status
)));
241 tmp
= ures_getByKey(top
, kZONES
, tmp
, &status
); // get Zones object from top
242 U_DEBUG_TZ_MSG(("gzbn: loaded ZONES, size %d, type %d, path %s %s\n", ures_getSize(tmp
), ures_getType(tmp
), ures_getPath(tmp
), u_errorName(status
)));
243 oldbundle
= ures_getByIndex(tmp
, idx
, oldbundle
, &status
); // get nth Zone object
244 U_DEBUG_TZ_MSG(("gzbn: loaded z#%d, size %d, type %d, path %s, %s\n", idx
, ures_getSize(oldbundle
), ures_getType(oldbundle
), ures_getPath(oldbundle
), u_errorName(status
)));
247 if(U_FAILURE(status
)) {
248 //ures_close(oldbundle);
256 UResourceBundle
* TimeZone::loadRule(const UResourceBundle
* top
, const UnicodeString
& ruleid
, UResourceBundle
* oldbundle
, UErrorCode
& status
) {
258 ruleid
.extract(0, sizeof(key
)-1, key
, (int32_t)sizeof(key
)-1, US_INV
);
259 U_DEBUG_TZ_MSG(("loadRule(%s)\n", key
));
260 UResourceBundle
*r
= ures_getByKey(top
, kRULES
, oldbundle
, &status
);
261 U_DEBUG_TZ_MSG(("loadRule(%s) -> kRULES [%s]\n", key
, u_errorName(status
)));
262 r
= ures_getByKey(r
, key
, r
, &status
);
263 U_DEBUG_TZ_MSG(("loadRule(%s) -> item [%s]\n", key
, u_errorName(status
)));
268 * Given an ID, open the appropriate resource for the given time zone.
269 * Dereference aliases if necessary.
271 * @param res resource, which must be ready for use (initialized but not open)
272 * @param ec input-output error code
273 * @return top-level resource bundle
275 static UResourceBundle
* openOlsonResource(const UnicodeString
& id
,
276 UResourceBundle
& res
,
281 id
.extract(0, sizeof(buf
)-1, buf
, sizeof(buf
), "");
283 UResourceBundle
*top
= ures_openDirect(0, kZONEINFO
, &ec
);
284 U_DEBUG_TZ_MSG(("pre: res sz=%d\n", ures_getSize(&res
)));
285 /* &res = */ getZoneByName(top
, id
, &res
, ec
);
286 // Dereference if this is an alias. Docs say result should be 1
287 // but it is 0 in 2.8 (?).
288 U_DEBUG_TZ_MSG(("Loading zone '%s' (%s, size %d) - %s\n", buf
, ures_getKey((UResourceBundle
*)&res
), ures_getSize(&res
), u_errorName(ec
)));
289 if (ures_getType(&res
) == URES_INT
) {
290 int32_t deref
= ures_getInt(&res
, &ec
) + 0;
291 U_DEBUG_TZ_MSG(("getInt: %s - type is %d\n", u_errorName(ec
), ures_getType(&res
)));
292 UResourceBundle
*ares
= ures_getByKey(top
, kZONES
, NULL
, &ec
); // dereference Zones section
293 ures_getByIndex(ares
, deref
, &res
, &ec
);
295 U_DEBUG_TZ_MSG(("alias to #%d (%s) - %s\n", deref
, "??", u_errorName(ec
)));
297 U_DEBUG_TZ_MSG(("not an alias - size %d\n", ures_getSize(&res
)));
299 U_DEBUG_TZ_MSG(("%s - final status is %s\n", buf
, u_errorName(ec
)));
303 // -------------------------------------
308 ensureStaticTimeZones() {
310 UMTX_CHECK(&LOCK
, (_GMT
== NULL
), needsInit
); /* This is here to prevent race conditions. */
312 // Initialize _GMT independently of other static data; it should
313 // be valid even if we can't load the time zone UDataMemory.
315 SimpleTimeZone
*tmpUnknown
=
316 new SimpleTimeZone(0, UnicodeString(TRUE
, UNKNOWN_ZONE_ID
, UNKNOWN_ZONE_ID_LENGTH
));
317 SimpleTimeZone
*tmpGMT
= new SimpleTimeZone(0, UnicodeString(TRUE
, GMT_ID
, GMT_ID_LENGTH
));
319 if (_UNKNOWN_ZONE
== 0) {
320 _UNKNOWN_ZONE
= tmpUnknown
;
328 ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE
, timeZone_cleanup
);
334 } // anonymous namespace
336 const TimeZone
& U_EXPORT2
337 TimeZone::getUnknown()
339 ensureStaticTimeZones();
340 return *_UNKNOWN_ZONE
;
343 const TimeZone
* U_EXPORT2
344 TimeZone::getGMT(void)
346 ensureStaticTimeZones();
350 // *****************************************************************************
352 // *****************************************************************************
354 UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(TimeZone
)
361 // -------------------------------------
363 TimeZone::TimeZone(const UnicodeString
&id
)
368 // -------------------------------------
370 TimeZone::~TimeZone()
374 // -------------------------------------
376 TimeZone::TimeZone(const TimeZone
&source
)
377 : UObject(source
), fID(source
.fID
)
381 // -------------------------------------
384 TimeZone::operator=(const TimeZone
&right
)
386 if (this != &right
) fID
= right
.fID
;
390 // -------------------------------------
393 TimeZone::operator==(const TimeZone
& that
) const
395 return typeid(*this) == typeid(that
) &&
399 // -------------------------------------
402 TimeZone::createTimeZone(const UnicodeString
& ID
)
404 /* We first try to lookup the zone ID in our system list. If this
405 * fails, we try to parse it as a custom string GMT[+-]hh:mm. If
406 * all else fails, we return GMT, which is probably not what the
407 * user wants, but at least is a functioning TimeZone object.
409 * We cannot return NULL, because that would break compatibility
412 TimeZone
* result
= createSystemTimeZone(ID
);
415 U_DEBUG_TZ_MSG(("failed to load system time zone with id - falling to custom"));
416 result
= createCustomTimeZone(ID
);
419 U_DEBUG_TZ_MSG(("failed to load time zone with id - falling to Etc/Unknown(GMT)"));
420 result
= getUnknown().clone();
426 * Lookup the given name in our system zone table. If found,
427 * instantiate a new zone of that name and return it. If not
431 TimeZone::createSystemTimeZone(const UnicodeString
& id
) {
432 UErrorCode ec
= U_ZERO_ERROR
;
433 return createSystemTimeZone(id
, ec
);
437 TimeZone::createSystemTimeZone(const UnicodeString
& id
, UErrorCode
& ec
) {
443 ures_initStackObject(&res
);
444 U_DEBUG_TZ_MSG(("pre-err=%s\n", u_errorName(ec
)));
445 UResourceBundle
*top
= openOlsonResource(id
, res
, ec
);
446 U_DEBUG_TZ_MSG(("post-err=%s\n", u_errorName(ec
)));
448 z
= new OlsonTimeZone(top
, &res
, id
, ec
);
450 U_DEBUG_TZ_MSG(("cstz: olson time zone failed to initialize - err %s\n", u_errorName(ec
)));
456 U_DEBUG_TZ_MSG(("cstz: failed to create, err %s\n", u_errorName(ec
)));
463 // -------------------------------------
466 * Initialize DEFAULT_ZONE from the system default time zone. The
467 * caller should confirm that DEFAULT_ZONE is NULL before calling.
468 * Upon return, DEFAULT_ZONE will not be NULL, unless operator new()
471 * Must be called OUTSIDE mutex.
474 TimeZone::initDefault()
476 // We access system timezone data through TPlatformUtilities,
477 // including tzset(), timezone, and tzname[].
478 int32_t rawOffset
= 0;
481 // First, try to create a system timezone, based
482 // on the string ID in tzname[0].
484 // NOTE: Local mutex here. TimeZone mutex below
485 // mutexed to avoid threading issues in the platform functions.
486 // Some of the locale/timezone OS functions may not be thread safe,
487 // so the intent is that any setting from anywhere within ICU
488 // happens while the ICU mutex is held.
489 // The operating system might actually use ICU to implement timezones.
490 // So we may have ICU calling ICU here, like on AIX.
491 // In order to prevent a double lock of a non-reentrant mutex in a
492 // different part of ICU, we use TZSET_LOCK to allow only one instance
493 // of ICU to query these thread unsafe OS functions at any given time.
494 Mutex
lock(&TZSET_LOCK
);
496 ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE
, timeZone_cleanup
);
497 uprv_tzset(); // Initialize tz... system data
499 // Get the timezone ID from the host. This function should do
500 // any required host-specific remapping; e.g., on Windows this
501 // function maps the Date and Time control panel setting to an
503 hostID
= uprv_tzname(0);
505 // Invert sign because UNIX semantics are backwards
506 rawOffset
= uprv_timezone() * -U_MILLIS_PER_SECOND
;
510 UMTX_CHECK(&LOCK
, (DEFAULT_ZONE
!= NULL
), initialized
);
512 /* Hrmph? Either a race condition happened, or tzset initialized ICU. */
516 TimeZone
* default_zone
= NULL
;
518 /* Make sure that the string is NULL terminated to prevent BoundsChecker/Purify warnings. */
519 UnicodeString
hostStrID(hostID
, -1, US_INV
);
520 hostStrID
.append((UChar
)0);
521 hostStrID
.truncate(hostStrID
.length()-1);
522 default_zone
= createSystemTimeZone(hostStrID
);
524 #if U_PLATFORM_USES_ONLY_WIN32_API
525 // hostID points to a heap-allocated location on Windows.
526 uprv_free(const_cast<char *>(hostID
));
529 int32_t hostIDLen
= hostStrID
.length();
530 if (default_zone
!= NULL
&& rawOffset
!= default_zone
->getRawOffset()
531 && (3 <= hostIDLen
&& hostIDLen
<= 4))
533 // Uh oh. This probably wasn't a good id.
534 // It was probably an ambiguous abbreviation
539 // Construct a fixed standard zone with the host's ID
541 if (default_zone
== NULL
) {
542 default_zone
= new SimpleTimeZone(rawOffset
, hostStrID
);
545 // If we _still_ don't have a time zone, use GMT.
546 if (default_zone
== NULL
) {
547 const TimeZone
* temptz
= getGMT();
548 // If we can't use GMT, get out.
549 if (temptz
== NULL
) {
552 default_zone
= temptz
->clone();
555 // If DEFAULT_ZONE is still NULL, set it up.
557 if (DEFAULT_ZONE
== NULL
) {
558 DEFAULT_ZONE
= default_zone
;
560 ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE
, timeZone_cleanup
);
567 // -------------------------------------
570 TimeZone::createDefault()
572 /* This is here to prevent race conditions. */
574 UMTX_CHECK(&LOCK
, (DEFAULT_ZONE
== NULL
), needsInit
);
579 Mutex
lock(&LOCK
); // In case adoptDefault is called
580 return (DEFAULT_ZONE
!= NULL
) ? DEFAULT_ZONE
->clone() : NULL
;
583 // -------------------------------------
586 TimeZone::adoptDefault(TimeZone
* zone
)
590 TimeZone
* old
= NULL
;
598 ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE
, timeZone_cleanup
);
601 // -------------------------------------
604 TimeZone::setDefault(const TimeZone
& zone
)
606 adoptDefault(zone
.clone());
609 //----------------------------------------------------------------------
612 * This is the default implementation for subclasses that do not
613 * override this method. This implementation calls through to the
614 * 8-argument getOffset() method after suitable computations, and
615 * correctly adjusts GMT millis to local millis when necessary.
617 void TimeZone::getOffset(UDate date
, UBool local
, int32_t& rawOffset
,
618 int32_t& dstOffset
, UErrorCode
& ec
) const {
623 rawOffset
= getRawOffset();
625 date
+= rawOffset
; // now in local standard millis
628 // When local == TRUE, date might not be in local standard
629 // millis. getOffset taking 7 parameters used here assume
630 // the given time in day is local standard time.
631 // At STD->DST transition, there is a range of time which
632 // does not exist. When 'date' is in this time range
633 // (and local == TRUE), this method interprets the specified
634 // local time as DST. At DST->STD transition, there is a
635 // range of time which occurs twice. In this case, this
636 // method interprets the specified local time as STD.
637 // To support the behavior above, we need to call getOffset
638 // (with 7 args) twice when local == true and DST is
639 // detected in the initial call.
640 for (int32_t pass
=0; ; ++pass
) {
641 int32_t year
, month
, dom
, dow
;
642 double day
= uprv_floor(date
/ U_MILLIS_PER_DAY
);
643 int32_t millis
= (int32_t) (date
- day
* U_MILLIS_PER_DAY
);
645 Grego::dayToFields(day
, year
, month
, dom
, dow
);
647 dstOffset
= getOffset(GregorianCalendar::AD
, year
, month
, dom
,
648 (uint8_t) dow
, millis
,
649 Grego::monthLength(year
, month
),
652 // Recompute if local==TRUE, dstOffset!=0.
653 if (pass
!=0 || !local
|| dstOffset
== 0) {
656 // adjust to local standard millis
661 // -------------------------------------
663 // New available IDs API as of ICU 2.4. Uses StringEnumeration API.
665 class TZEnumeration
: public StringEnumeration
{
668 // Map into to zones. Our results are zone[map[i]] for
669 // i=0..len-1, where zone[i] is the i-th Olson zone. If map==NULL
670 // then our results are zone[i] for i=0..len-1. Len will be zero
671 // if the zone data could not be loaded.
677 TZEnumeration(int32_t* mapData
, int32_t mapLen
, UBool adoptMapData
) : pos(0) {
679 localMap
= adoptMapData
? mapData
: NULL
;
683 UBool
getID(int32_t i
) {
684 UErrorCode ec
= U_ZERO_ERROR
;
686 const UChar
* id
= NULL
;
687 UResourceBundle
*top
= ures_openDirect(0, kZONEINFO
, &ec
);
688 top
= ures_getByKey(top
, kNAMES
, top
, &ec
); // dereference Zones section
689 id
= ures_getStringByIndex(top
, i
, &idLen
, &ec
);
694 unistr
.fastCopyFrom(UnicodeString(TRUE
, id
, idLen
));
697 return U_SUCCESS(ec
);
700 static int32_t* getMap(USystemTimeZoneType type
, int32_t& len
, UErrorCode
& ec
) {
707 case UCAL_ZONE_TYPE_ANY
:
708 m
= MAP_SYSTEM_ZONES
;
709 len
= LEN_SYSTEM_ZONES
;
711 case UCAL_ZONE_TYPE_CANONICAL
:
712 m
= MAP_CANONICAL_SYSTEM_ZONES
;
713 len
= LEN_CANONICAL_SYSTEM_ZONES
;
715 case UCAL_ZONE_TYPE_CANONICAL_LOCATION
:
716 m
= MAP_CANONICAL_SYSTEM_LOCATION_ZONES
;
717 len
= LEN_CANONICAL_SYSTEM_LOCATION_ZONES
;
720 UBool needsInit
= FALSE
;
721 UMTX_CHECK(&LOCK
, (len
== 0), needsInit
);
723 m
= initMap(type
, len
, ec
);
728 static int32_t* initMap(USystemTimeZoneType type
, int32_t& len
, UErrorCode
& ec
) {
734 int32_t *result
= NULL
;
736 UResourceBundle
*res
= ures_openDirect(0, kZONEINFO
, &ec
);
737 res
= ures_getByKey(res
, kNAMES
, res
, &ec
); // dereference Zones section
739 int32_t size
= ures_getSize(res
);
740 int32_t *m
= (int32_t *)uprv_malloc(size
* sizeof(int32_t));
742 ec
= U_MEMORY_ALLOCATION_ERROR
;
744 int32_t numEntries
= 0;
745 for (int32_t i
= 0; i
< size
; i
++) {
746 UnicodeString id
= ures_getUnicodeStringByIndex(res
, i
, &ec
);
750 if (0 == id
.compare(UNKNOWN_ZONE_ID
, UNKNOWN_ZONE_ID_LENGTH
)) {
751 // exclude Etc/Unknown
754 if (type
== UCAL_ZONE_TYPE_CANONICAL
|| type
== UCAL_ZONE_TYPE_CANONICAL_LOCATION
) {
755 UnicodeString canonicalID
;
756 ZoneMeta::getCanonicalCLDRID(id
, canonicalID
, ec
);
760 if (canonicalID
!= id
) {
765 if (type
== UCAL_ZONE_TYPE_CANONICAL_LOCATION
) {
766 const UChar
*region
= TimeZone::getRegion(id
, ec
);
770 if (u_strcmp(region
, WORLD
) == 0) {
771 // exclude non-location ("001")
779 m
= (int32_t *)uprv_realloc(tmp
, numEntries
* sizeof(int32_t));
781 // realloc failed.. use the original one even it has unused
789 case UCAL_ZONE_TYPE_ANY
:
790 if (MAP_SYSTEM_ZONES
== NULL
) {
791 MAP_SYSTEM_ZONES
= m
;
792 LEN_SYSTEM_ZONES
= numEntries
;
794 ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE
, timeZone_cleanup
);
796 result
= MAP_SYSTEM_ZONES
;
797 len
= LEN_SYSTEM_ZONES
;
799 case UCAL_ZONE_TYPE_CANONICAL
:
800 if (MAP_CANONICAL_SYSTEM_ZONES
== NULL
) {
801 MAP_CANONICAL_SYSTEM_ZONES
= m
;
802 LEN_CANONICAL_SYSTEM_ZONES
= numEntries
;
804 ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE
, timeZone_cleanup
);
806 result
= MAP_CANONICAL_SYSTEM_ZONES
;
807 len
= LEN_CANONICAL_SYSTEM_ZONES
;
809 case UCAL_ZONE_TYPE_CANONICAL_LOCATION
:
810 if (MAP_CANONICAL_SYSTEM_LOCATION_ZONES
== NULL
) {
811 MAP_CANONICAL_SYSTEM_LOCATION_ZONES
= m
;
812 LEN_CANONICAL_SYSTEM_LOCATION_ZONES
= numEntries
;
814 ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE
, timeZone_cleanup
);
816 result
= MAP_CANONICAL_SYSTEM_LOCATION_ZONES
;
817 len
= LEN_CANONICAL_SYSTEM_LOCATION_ZONES
;
833 #define DEFAULT_FILTERED_MAP_SIZE 8
834 #define MAP_INCREMENT_SIZE 8
836 static TZEnumeration
* create(USystemTimeZoneType type
, const char* region
, const int32_t* rawOffset
, UErrorCode
& ec
) {
842 int32_t *baseMap
= getMap(type
, baseLen
, ec
);
848 // If any additional conditions are available,
849 // create instance local map filtered by the conditions.
851 int32_t *filteredMap
= NULL
;
852 int32_t numEntries
= 0;
854 if (region
!= NULL
|| rawOffset
!= NULL
) {
855 int32_t filteredMapSize
= DEFAULT_FILTERED_MAP_SIZE
;
856 filteredMap
= (int32_t *)uprv_malloc(filteredMapSize
* sizeof(int32_t));
857 if (filteredMap
== NULL
) {
858 ec
= U_MEMORY_ALLOCATION_ERROR
;
862 // Walk through the base map
863 UResourceBundle
*res
= ures_openDirect(0, kZONEINFO
, &ec
);
864 res
= ures_getByKey(res
, kNAMES
, res
, &ec
); // dereference Zones section
865 for (int32_t i
= 0; i
< baseLen
; i
++) {
866 int32_t zidx
= baseMap
[i
];
867 UnicodeString id
= ures_getUnicodeStringByIndex(res
, zidx
, &ec
);
871 if (region
!= NULL
) {
873 char tzregion
[4]; // max 3 letters + null term
874 TimeZone::getRegion(id
, tzregion
, sizeof(tzregion
), ec
);
878 if (uprv_stricmp(tzregion
, region
) != 0) {
879 // region does not match
883 if (rawOffset
!= NULL
) {
884 // Filter by raw offset
885 // Note: This is VERY inefficient
886 TimeZone
*z
= TimeZone::createSystemTimeZone(id
, ec
);
890 int32_t tzoffset
= z
->getRawOffset();
893 if (tzoffset
!= *rawOffset
) {
898 if (filteredMapSize
<= numEntries
) {
899 filteredMapSize
+= MAP_INCREMENT_SIZE
;
900 int32_t *tmp
= (int32_t *)uprv_realloc(filteredMap
, filteredMapSize
* sizeof(int32_t));
902 ec
= U_MEMORY_ALLOCATION_ERROR
;
909 filteredMap
[numEntries
++] = zidx
;
913 uprv_free(filteredMap
);
920 TZEnumeration
*result
= NULL
;
922 // Finally, create a new enumeration instance
923 if (filteredMap
== NULL
) {
924 result
= new TZEnumeration(baseMap
, baseLen
, FALSE
);
926 result
= new TZEnumeration(filteredMap
, numEntries
, TRUE
);
929 if (result
== NULL
) {
930 ec
= U_MEMORY_ALLOCATION_ERROR
;
934 if (filteredMap
!= NULL
) {
935 uprv_free(filteredMap
);
941 TZEnumeration(const TZEnumeration
&other
) : StringEnumeration(), map(NULL
), localMap(NULL
), len(0), pos(0) {
942 if (other
.localMap
!= NULL
) {
943 localMap
= (int32_t *)uprv_malloc(other
.len
* sizeof(int32_t));
944 if (localMap
!= NULL
) {
946 uprv_memcpy(localMap
, other
.localMap
, len
* sizeof(int32_t));
962 virtual ~TZEnumeration();
964 virtual StringEnumeration
*clone() const {
965 return new TZEnumeration(*this);
968 virtual int32_t count(UErrorCode
& status
) const {
969 return U_FAILURE(status
) ? 0 : len
;
972 virtual const UnicodeString
* snext(UErrorCode
& status
) {
973 if (U_SUCCESS(status
) && map
!= NULL
&& pos
< len
) {
981 virtual void reset(UErrorCode
& /*status*/) {
986 static UClassID U_EXPORT2
getStaticClassID(void);
987 virtual UClassID
getDynamicClassID(void) const;
990 TZEnumeration::~TZEnumeration() {
991 if (localMap
!= NULL
) {
996 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TZEnumeration
)
998 StringEnumeration
* U_EXPORT2
999 TimeZone::createTimeZoneIDEnumeration(
1000 USystemTimeZoneType zoneType
,
1002 const int32_t* rawOffset
,
1004 return TZEnumeration::create(zoneType
, region
, rawOffset
, ec
);
1007 StringEnumeration
* U_EXPORT2
1008 TimeZone::createEnumeration() {
1009 UErrorCode ec
= U_ZERO_ERROR
;
1010 return TZEnumeration::create(UCAL_ZONE_TYPE_ANY
, NULL
, NULL
, ec
);
1013 StringEnumeration
* U_EXPORT2
1014 TimeZone::createEnumeration(int32_t rawOffset
) {
1015 UErrorCode ec
= U_ZERO_ERROR
;
1016 return TZEnumeration::create(UCAL_ZONE_TYPE_ANY
, NULL
, &rawOffset
, ec
);
1019 StringEnumeration
* U_EXPORT2
1020 TimeZone::createEnumeration(const char* country
) {
1021 UErrorCode ec
= U_ZERO_ERROR
;
1022 return TZEnumeration::create(UCAL_ZONE_TYPE_ANY
, country
, NULL
, ec
);
1025 // ---------------------------------------
1028 TimeZone::countEquivalentIDs(const UnicodeString
& id
) {
1030 UErrorCode ec
= U_ZERO_ERROR
;
1031 UResourceBundle res
;
1032 ures_initStackObject(&res
);
1033 U_DEBUG_TZ_MSG(("countEquivalentIDs..\n"));
1034 UResourceBundle
*top
= openOlsonResource(id
, res
, ec
);
1035 if (U_SUCCESS(ec
)) {
1037 ures_initStackObject(&r
);
1038 ures_getByKey(&res
, kLINKS
, &r
, &ec
);
1039 ures_getIntVector(&r
, &result
, &ec
);
1047 // ---------------------------------------
1049 const UnicodeString U_EXPORT2
1050 TimeZone::getEquivalentID(const UnicodeString
& id
, int32_t index
) {
1051 U_DEBUG_TZ_MSG(("gEI(%d)\n", index
));
1052 UnicodeString result
;
1053 UErrorCode ec
= U_ZERO_ERROR
;
1054 UResourceBundle res
;
1055 ures_initStackObject(&res
);
1056 UResourceBundle
*top
= openOlsonResource(id
, res
, ec
);
1058 if (U_SUCCESS(ec
)) {
1060 ures_initStackObject(&r
);
1062 ures_getByKey(&res
, kLINKS
, &r
, &ec
);
1063 const int32_t* v
= ures_getIntVector(&r
, &size
, &ec
);
1064 if (U_SUCCESS(ec
)) {
1065 if (index
>= 0 && index
< size
) {
1073 UResourceBundle
*ares
= ures_getByKey(top
, kNAMES
, NULL
, &ec
); // dereference Zones section
1074 if (U_SUCCESS(ec
)) {
1076 const UChar
* id
= ures_getStringByIndex(ares
, zone
, &idLen
, &ec
);
1077 result
.fastCopyFrom(UnicodeString(TRUE
, id
, idLen
));
1078 U_DEBUG_TZ_MSG(("gei(%d) -> %d, len%d, %s\n", index
, zone
, result
.length(), u_errorName(ec
)));
1083 #if defined(U_DEBUG_TZ)
1084 if(result
.length() ==0) {
1085 U_DEBUG_TZ_MSG(("equiv [__, #%d] -> 0 (%s)\n", index
, u_errorName(ec
)));
1091 // ---------------------------------------
1093 // These methods are used by ZoneMeta class only.
1096 TimeZone::findID(const UnicodeString
& id
) {
1097 const UChar
*result
= NULL
;
1098 UErrorCode ec
= U_ZERO_ERROR
;
1099 UResourceBundle
*rb
= ures_openDirect(NULL
, kZONEINFO
, &ec
);
1101 // resolve zone index by name
1102 UResourceBundle
*names
= ures_getByKey(rb
, kNAMES
, NULL
, &ec
);
1103 int32_t idx
= findInStringArray(names
, id
, ec
);
1104 result
= ures_getStringByIndex(names
, idx
, NULL
, &ec
);
1105 if (U_FAILURE(ec
)) {
1115 TimeZone::dereferOlsonLink(const UnicodeString
& id
) {
1116 const UChar
*result
= NULL
;
1117 UErrorCode ec
= U_ZERO_ERROR
;
1118 UResourceBundle
*rb
= ures_openDirect(NULL
, kZONEINFO
, &ec
);
1120 // resolve zone index by name
1121 UResourceBundle
*names
= ures_getByKey(rb
, kNAMES
, NULL
, &ec
);
1122 int32_t idx
= findInStringArray(names
, id
, ec
);
1123 result
= ures_getStringByIndex(names
, idx
, NULL
, &ec
);
1125 // open the zone bundle by index
1126 ures_getByKey(rb
, kZONES
, rb
, &ec
);
1127 ures_getByIndex(rb
, idx
, rb
, &ec
);
1129 if (U_SUCCESS(ec
)) {
1130 if (ures_getType(rb
) == URES_INT
) {
1131 // this is a link - dereference the link
1132 int32_t deref
= ures_getInt(rb
, &ec
);
1133 const UChar
* tmp
= ures_getStringByIndex(names
, deref
, NULL
, &ec
);
1134 if (U_SUCCESS(ec
)) {
1147 TimeZone::getRegion(const UnicodeString
& id
) {
1148 UErrorCode status
= U_ZERO_ERROR
;
1149 return getRegion(id
, status
);
1153 TimeZone::getRegion(const UnicodeString
& id
, UErrorCode
& status
) {
1154 if (U_FAILURE(status
)) {
1157 const UChar
*result
= NULL
;
1158 UResourceBundle
*rb
= ures_openDirect(NULL
, kZONEINFO
, &status
);
1160 // resolve zone index by name
1161 UResourceBundle
*res
= ures_getByKey(rb
, kNAMES
, NULL
, &status
);
1162 int32_t idx
= findInStringArray(res
, id
, status
);
1164 // get region mapping
1165 ures_getByKey(rb
, kREGIONS
, res
, &status
);
1166 const UChar
*tmp
= ures_getStringByIndex(res
, idx
, NULL
, &status
);
1167 if (U_SUCCESS(status
)) {
1178 // ---------------------------------------
1180 TimeZone::getRegion(const UnicodeString
& id
, char *region
, int32_t capacity
, UErrorCode
& status
)
1182 int32_t resultLen
= 0;
1184 if (U_FAILURE(status
)) {
1188 const UChar
*uregion
= NULL
;
1189 // "Etc/Unknown" is not a system zone ID,
1190 // but in the zone data
1191 if (id
.compare(UNKNOWN_ZONE_ID
, UNKNOWN_ZONE_ID_LENGTH
) != 0) {
1192 uregion
= getRegion(id
);
1194 if (uregion
== NULL
) {
1195 status
= U_ILLEGAL_ARGUMENT_ERROR
;
1198 resultLen
= u_strlen(uregion
);
1199 // A region code is represented by invariant characters
1200 u_UCharsToChars(uregion
, region
, uprv_min(resultLen
, capacity
));
1202 if (capacity
< resultLen
) {
1203 status
= U_BUFFER_OVERFLOW_ERROR
;
1207 return u_terminateChars(region
, capacity
, resultLen
, &status
);
1210 // ---------------------------------------
1214 TimeZone::getDisplayName(UnicodeString
& result
) const
1216 return getDisplayName(FALSE
,LONG
,Locale::getDefault(), result
);
1220 TimeZone::getDisplayName(const Locale
& locale
, UnicodeString
& result
) const
1222 return getDisplayName(FALSE
, LONG
, locale
, result
);
1226 TimeZone::getDisplayName(UBool daylight
, EDisplayType style
, UnicodeString
& result
) const
1228 return getDisplayName(daylight
,style
, Locale::getDefault(), result
);
1230 //--------------------------------------
1232 TimeZone::getDSTSavings()const {
1233 if (useDaylightTime()) {
1238 //---------------------------------------
1240 TimeZone::getDisplayName(UBool daylight
, EDisplayType style
, const Locale
& locale
, UnicodeString
& result
) const
1242 UErrorCode status
= U_ZERO_ERROR
;
1243 UDate date
= Calendar::getNow();
1244 UTimeZoneFormatTimeType timeType
;
1247 if (style
== GENERIC_LOCATION
|| style
== LONG_GENERIC
|| style
== SHORT_GENERIC
) {
1248 LocalPointer
<TimeZoneFormat
> tzfmt(TimeZoneFormat::createInstance(locale
, status
));
1249 if (U_FAILURE(status
)) {
1255 case GENERIC_LOCATION
:
1256 tzfmt
->format(UTZFMT_STYLE_GENERIC_LOCATION
, *this, date
, result
, &timeType
);
1259 tzfmt
->format(UTZFMT_STYLE_GENERIC_LONG
, *this, date
, result
, &timeType
);
1262 tzfmt
->format(UTZFMT_STYLE_GENERIC_SHORT
, *this, date
, result
, &timeType
);
1267 // Generic format many use Localized GMT as the final fallback.
1268 // When Localized GMT format is used, the result might not be
1269 // appropriate for the requested daylight value.
1270 if ((daylight
&& timeType
== UTZFMT_TIME_TYPE_STANDARD
) || (!daylight
&& timeType
== UTZFMT_TIME_TYPE_DAYLIGHT
)) {
1271 offset
= daylight
? getRawOffset() + getDSTSavings() : getRawOffset();
1272 tzfmt
->formatOffsetLocalizedGMT(offset
, result
, status
);
1274 } else if (style
== LONG_GMT
|| style
== SHORT_GMT
) {
1275 LocalPointer
<TimeZoneFormat
> tzfmt(TimeZoneFormat::createInstance(locale
, status
));
1276 if (U_FAILURE(status
)) {
1280 offset
= daylight
&& useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
1283 tzfmt
->formatOffsetLocalizedGMT(offset
, result
, status
);
1286 tzfmt
->formatOffsetRFC822(offset
, result
, status
);
1293 U_ASSERT(style
== LONG
|| style
== SHORT
|| style
== SHORT_COMMONLY_USED
);
1294 UTimeZoneNameType nameType
= UTZNM_UNKNOWN
;
1297 nameType
= daylight
? UTZNM_LONG_DAYLIGHT
: UTZNM_LONG_STANDARD
;
1300 case SHORT_COMMONLY_USED
:
1301 nameType
= daylight
? UTZNM_SHORT_DAYLIGHT
: UTZNM_SHORT_STANDARD
;
1306 LocalPointer
<TimeZoneNames
> tznames(TimeZoneNames::createInstance(locale
, status
));
1307 if (U_FAILURE(status
)) {
1311 UnicodeString
canonicalID(ZoneMeta::getCanonicalCLDRID(*this));
1312 tznames
->getDisplayName(canonicalID
, nameType
, date
, result
);
1313 if (result
.isEmpty()) {
1314 // Fallback to localized GMT
1315 LocalPointer
<TimeZoneFormat
> tzfmt(TimeZoneFormat::createInstance(locale
, status
));
1316 offset
= daylight
&& useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
1317 tzfmt
->formatOffsetLocalizedGMT(offset
, result
, status
);
1320 if (U_FAILURE(status
)) {
1327 * Parse a custom time zone identifier and return a corresponding zone.
1328 * @param id a string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
1330 * @return a newly created SimpleTimeZone with the given offset and
1331 * no Daylight Savings Time, or null if the id cannot be parsed.
1334 TimeZone::createCustomTimeZone(const UnicodeString
& id
)
1336 int32_t sign
, hour
, min
, sec
;
1337 if (parseCustomID(id
, sign
, hour
, min
, sec
)) {
1338 UnicodeString customID
;
1339 formatCustomID(hour
, min
, sec
, (sign
< 0), customID
);
1340 int32_t offset
= sign
* ((hour
* 60 + min
) * 60 + sec
) * 1000;
1341 return new SimpleTimeZone(offset
, customID
);
1347 TimeZone::getCustomID(const UnicodeString
& id
, UnicodeString
& normalized
, UErrorCode
& status
) {
1348 normalized
.remove();
1349 if (U_FAILURE(status
)) {
1352 int32_t sign
, hour
, min
, sec
;
1353 if (parseCustomID(id
, sign
, hour
, min
, sec
)) {
1354 formatCustomID(hour
, min
, sec
, (sign
< 0), normalized
);
1360 TimeZone::parseCustomID(const UnicodeString
& id
, int32_t& sign
,
1361 int32_t& hour
, int32_t& min
, int32_t& sec
) {
1362 static const int32_t kParseFailed
= -99999;
1364 NumberFormat
* numberFormat
= 0;
1365 UnicodeString idUppercase
= id
;
1366 idUppercase
.toUpper("");
1368 if (id
.length() > GMT_ID_LENGTH
&&
1369 idUppercase
.startsWith(GMT_ID
, GMT_ID_LENGTH
))
1371 ParsePosition
pos(GMT_ID_LENGTH
);
1377 if (id
[pos
.getIndex()] == MINUS
/*'-'*/) {
1379 } else if (id
[pos
.getIndex()] != PLUS
/*'+'*/) {
1382 pos
.setIndex(pos
.getIndex() + 1);
1384 UErrorCode success
= U_ZERO_ERROR
;
1385 numberFormat
= NumberFormat::createInstance(success
);
1386 if(U_FAILURE(success
)){
1389 numberFormat
->setParseIntegerOnly(TRUE
);
1390 //numberFormat->setLenient(TRUE); // TODO: May need to set this, depends on latest timezone parsing
1392 // Look for either hh:mm, hhmm, or hh
1393 int32_t start
= pos
.getIndex();
1394 Formattable
n(kParseFailed
);
1395 numberFormat
->parse(id
, n
, pos
);
1396 if (pos
.getIndex() == start
) {
1397 delete numberFormat
;
1402 if (pos
.getIndex() < id
.length()) {
1403 if (pos
.getIndex() - start
> 2
1404 || id
[pos
.getIndex()] != COLON
) {
1405 delete numberFormat
;
1409 pos
.setIndex(pos
.getIndex() + 1);
1410 int32_t oldPos
= pos
.getIndex();
1411 n
.setLong(kParseFailed
);
1412 numberFormat
->parse(id
, n
, pos
);
1413 if ((pos
.getIndex() - oldPos
) != 2) {
1415 delete numberFormat
;
1419 if (pos
.getIndex() < id
.length()) {
1420 if (id
[pos
.getIndex()] != COLON
) {
1421 delete numberFormat
;
1425 pos
.setIndex(pos
.getIndex() + 1);
1426 oldPos
= pos
.getIndex();
1427 n
.setLong(kParseFailed
);
1428 numberFormat
->parse(id
, n
, pos
);
1429 if (pos
.getIndex() != id
.length()
1430 || (pos
.getIndex() - oldPos
) != 2) {
1431 delete numberFormat
;
1437 // Supported formats are below -
1446 int32_t length
= pos
.getIndex() - start
;
1447 if (length
<= 0 || 6 < length
) {
1449 delete numberFormat
;
1455 // already set to hour
1465 min
= (hour
/100) % 100;
1471 delete numberFormat
;
1473 if (hour
> kMAX_CUSTOM_HOUR
|| min
> kMAX_CUSTOM_MIN
|| sec
> kMAX_CUSTOM_SEC
) {
1482 TimeZone::formatCustomID(int32_t hour
, int32_t min
, int32_t sec
,
1483 UBool negative
, UnicodeString
& id
) {
1484 // Create time zone ID - GMT[+|-]hhmm[ss]
1485 id
.setTo(GMT_ID
, GMT_ID_LENGTH
);
1486 if (hour
| min
| sec
) {
1494 id
+= (UChar
)ZERO_DIGIT
;
1496 id
+= (UChar
)(ZERO_DIGIT
+ hour
/10);
1498 id
+= (UChar
)(ZERO_DIGIT
+ hour%10
);
1501 id
+= (UChar
)ZERO_DIGIT
;
1503 id
+= (UChar
)(ZERO_DIGIT
+ min
/10);
1505 id
+= (UChar
)(ZERO_DIGIT
+ min%10
);
1510 id
+= (UChar
)ZERO_DIGIT
;
1512 id
+= (UChar
)(ZERO_DIGIT
+ sec
/10);
1514 id
+= (UChar
)(ZERO_DIGIT
+ sec%10
);
1522 TimeZone::hasSameRules(const TimeZone
& other
) const
1524 return (getRawOffset() == other
.getRawOffset() &&
1525 useDaylightTime() == other
.useDaylightTime());
1529 TimeZone::getTZDataVersion(UErrorCode
& status
)
1531 /* This is here to prevent race conditions. */
1533 UMTX_CHECK(&LOCK
, !TZDataVersionInitialized
, needsInit
);
1536 UResourceBundle
*bundle
= ures_openDirect(NULL
, kZONEINFO
, &status
);
1537 const UChar
*tzver
= ures_getStringByKey(bundle
, kTZVERSION
,
1540 if (U_SUCCESS(status
)) {
1541 if (len
>= (int32_t)sizeof(TZDATA_VERSION
)) {
1542 // Ensure that there is always space for a trailing nul in TZDATA_VERSION
1543 len
= sizeof(TZDATA_VERSION
) - 1;
1546 if (!TZDataVersionInitialized
) {
1547 u_UCharsToChars(tzver
, TZDATA_VERSION
, len
);
1548 TZDataVersionInitialized
= TRUE
;
1551 ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE
, timeZone_cleanup
);
1556 if (U_FAILURE(status
)) {
1559 return (const char*)TZDATA_VERSION
;
1563 TimeZone::getCanonicalID(const UnicodeString
& id
, UnicodeString
& canonicalID
, UErrorCode
& status
)
1565 UBool isSystemID
= FALSE
;
1566 return getCanonicalID(id
, canonicalID
, isSystemID
, status
);
1570 TimeZone::getCanonicalID(const UnicodeString
& id
, UnicodeString
& canonicalID
, UBool
& isSystemID
,
1573 canonicalID
.remove();
1575 if (U_FAILURE(status
)) {
1578 if (id
.compare(UNKNOWN_ZONE_ID
, UNKNOWN_ZONE_ID_LENGTH
) == 0) {
1579 // special case - Etc/Unknown is a canonical ID, but not system ID
1580 canonicalID
.fastCopyFrom(id
);
1583 ZoneMeta::getCanonicalCLDRID(id
, canonicalID
, status
);
1584 if (U_SUCCESS(status
)) {
1588 status
= U_ZERO_ERROR
;
1589 getCustomID(id
, canonicalID
, status
);
1597 #endif /* #if !UCONFIG_NO_FORMATTING */