1 /***********************************************************************
3 * Copyright (c) 1997-2014, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 ***********************************************************************/
7 #include "unicode/utypes.h"
9 #if !UCONFIG_NO_FORMATTING
11 #include "unicode/timezone.h"
12 #include "unicode/simpletz.h"
13 #include "unicode/calendar.h"
14 #include "unicode/gregocal.h"
15 #include "unicode/resbund.h"
16 #include "unicode/strenum.h"
17 #include "unicode/uversion.h"
24 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
26 #define CASE(id,test) case id: \
29 logln(#test "---"); logln(""); \
34 // *****************************************************************************
36 // *****************************************************************************
38 // Some test case data is current date/tzdata version sensitive and producing errors
39 // when year/rule are changed. Although we want to keep our eyes on test failures
40 // caused by tzdata changes while development, keep maintaining test data in maintenance
41 // stream is a little bit hassle. ICU 49 or later versions are using minor version field
42 // to indicate a development build (0) or official release build (others). For development
43 // builds, a test failure triggers an error, while release builds only report them in
44 // verbose mode with logln.
45 static UBool isDevelopmentBuild
= (U_ICU_VERSION_MINOR_NUM
== 0);
47 void TimeZoneTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
50 logln("TestSuite TestTimeZone");
53 TESTCASE_AUTO(TestPRTOffset
);
54 TESTCASE_AUTO(TestVariousAPI518
);
55 TESTCASE_AUTO(TestGetAvailableIDs913
);
56 TESTCASE_AUTO(TestGenericAPI
);
57 TESTCASE_AUTO(TestRuleAPI
);
58 TESTCASE_AUTO(TestShortZoneIDs
);
59 TESTCASE_AUTO(TestCustomParse
);
60 TESTCASE_AUTO(TestDisplayName
);
61 TESTCASE_AUTO(TestDSTSavings
);
62 TESTCASE_AUTO(TestAlternateRules
);
63 TESTCASE_AUTO(TestCountries
);
64 TESTCASE_AUTO(TestHistorical
);
65 TESTCASE_AUTO(TestEquivalentIDs
);
66 TESTCASE_AUTO(TestAliasedNames
);
67 TESTCASE_AUTO(TestFractionalDST
);
68 TESTCASE_AUTO(TestFebruary
);
69 TESTCASE_AUTO(TestCanonicalIDAPI
);
70 TESTCASE_AUTO(TestCanonicalID
);
71 TESTCASE_AUTO(TestDisplayNamesMeta
);
72 TESTCASE_AUTO(TestGetRegion
);
73 TESTCASE_AUTO(TestGetAvailableIDsNew
);
74 TESTCASE_AUTO(TestGetUnknown
);
75 TESTCASE_AUTO(TestGetWindowsID
);
76 TESTCASE_AUTO(TestGetIDForWindowsID
);
80 const int32_t TimeZoneTest::millisPerHour
= 3600000;
82 // ---------------------------------------------------------------------------------
85 * Generic API testing for API coverage.
88 TimeZoneTest::TestGenericAPI()
90 UnicodeString
id("NewGMT");
91 int32_t offset
= 12345;
93 SimpleTimeZone
*zone
= new SimpleTimeZone(offset
, id
);
94 if (zone
->useDaylightTime()) errln("FAIL: useDaylightTime should return FALSE");
96 TimeZone
* zoneclone
= zone
->clone();
97 if (!(*zoneclone
== *zone
)) errln("FAIL: clone or operator== failed");
98 zoneclone
->setID("abc");
99 if (!(*zoneclone
!= *zone
)) errln("FAIL: clone or operator!= failed");
102 zoneclone
= zone
->clone();
103 if (!(*zoneclone
== *zone
)) errln("FAIL: clone or operator== failed");
104 zoneclone
->setRawOffset(45678);
105 if (!(*zoneclone
!= *zone
)) errln("FAIL: clone or operator!= failed");
107 SimpleTimeZone
copy(*zone
);
108 if (!(copy
== *zone
)) errln("FAIL: copy constructor or operator== failed");
109 copy
= *(SimpleTimeZone
*)zoneclone
;
110 if (!(copy
== *zoneclone
)) errln("FAIL: assignment operator or operator== failed");
112 TimeZone
* saveDefault
= TimeZone::createDefault();
113 logln((UnicodeString
)"TimeZone::createDefault() => " + saveDefault
->getID(id
));
115 TimeZone::adoptDefault(zone
);
116 TimeZone
* defaultzone
= TimeZone::createDefault();
117 if (defaultzone
== zone
||
118 !(*defaultzone
== *zone
))
119 errln("FAIL: createDefault failed");
120 TimeZone::adoptDefault(saveDefault
);
124 logln("call uprv_timezone() which uses the host");
125 logln("to get the difference in seconds between coordinated universal");
126 logln("time and local time. E.g., -28,800 for PST (GMT-8hrs)");
128 int32_t tzoffset
= uprv_timezone();
129 if ((tzoffset
% 900) != 0) {
131 * Ticket#6364 and #7648
132 * A few time zones are using GMT offests not a multiple of 15 minutes.
133 * Therefore, we should not interpret such case as an error.
134 * We downgrade this from errln to infoln. When we see this message,
135 * we should examine if it is ignorable or not.
137 infoln("WARNING: t_timezone may be incorrect. It is not a multiple of 15min.", tzoffset
);
140 UErrorCode status
= U_ZERO_ERROR
;
141 const char* tzver
= TimeZone::getTZDataVersion(status
);
142 if (U_FAILURE(status
)) {
143 errcheckln(status
, "FAIL: getTZDataVersion failed - %s", u_errorName(status
));
144 } else if (uprv_strlen(tzver
) != 5 /* 4 digits + 1 letter */) {
145 errln((UnicodeString
)"FAIL: getTZDataVersion returned " + tzver
);
147 logln((UnicodeString
)"tzdata version: " + tzver
);
151 // ---------------------------------------------------------------------------------
154 * Test the setStartRule/setEndRule API calls.
157 TimeZoneTest::TestRuleAPI()
159 UErrorCode status
= U_ZERO_ERROR
;
161 UDate offset
= 60*60*1000*1.75; // Pick a weird offset
162 SimpleTimeZone
*zone
= new SimpleTimeZone((int32_t)offset
, "TestZone");
163 if (zone
->useDaylightTime()) errln("FAIL: useDaylightTime should return FALSE");
165 // Establish our expected transition times. Do this with a non-DST
166 // calendar with the (above) declared local offset.
167 GregorianCalendar
*gc
= new GregorianCalendar(*zone
, status
);
168 if (failure(status
, "new GregorianCalendar", TRUE
)) return;
170 gc
->set(1990, UCAL_MARCH
, 1);
171 UDate marchOneStd
= gc
->getTime(status
); // Local Std time midnight
173 gc
->set(1990, UCAL_JULY
, 1);
174 UDate julyOneStd
= gc
->getTime(status
); // Local Std time midnight
175 if (failure(status
, "GregorianCalendar::getTime")) return;
177 // Starting and ending hours, WALL TIME
178 int32_t startHour
= (int32_t)(2.25 * 3600000);
179 int32_t endHour
= (int32_t)(3.5 * 3600000);
181 zone
->setStartRule(UCAL_MARCH
, 1, 0, startHour
, status
);
182 zone
->setEndRule (UCAL_JULY
, 1, 0, endHour
, status
);
185 gc
= new GregorianCalendar(*zone
, status
);
186 if (failure(status
, "new GregorianCalendar")) return;
188 UDate marchOne
= marchOneStd
+ startHour
;
189 UDate julyOne
= julyOneStd
+ endHour
- 3600000; // Adjust from wall to Std time
191 UDate expMarchOne
= 636251400000.0;
192 if (marchOne
!= expMarchOne
)
194 errln((UnicodeString
)"FAIL: Expected start computed as " + marchOne
+
195 " = " + dateToString(marchOne
));
196 logln((UnicodeString
)" Should be " + expMarchOne
+
197 " = " + dateToString(expMarchOne
));
200 UDate expJulyOne
= 646793100000.0;
201 if (julyOne
!= expJulyOne
)
203 errln((UnicodeString
)"FAIL: Expected start computed as " + julyOne
+
204 " = " + dateToString(julyOne
));
205 logln((UnicodeString
)" Should be " + expJulyOne
+
206 " = " + dateToString(expJulyOne
));
209 testUsingBinarySearch(*zone
, date(90, UCAL_JANUARY
, 1), date(90, UCAL_JUNE
, 15), marchOne
);
210 testUsingBinarySearch(*zone
, date(90, UCAL_JUNE
, 1), date(90, UCAL_DECEMBER
, 31), julyOne
);
212 if (zone
->inDaylightTime(marchOne
- 1000, status
) ||
213 !zone
->inDaylightTime(marchOne
, status
))
214 errln("FAIL: Start rule broken");
215 if (!zone
->inDaylightTime(julyOne
- 1000, status
) ||
216 zone
->inDaylightTime(julyOne
, status
))
217 errln("FAIL: End rule broken");
219 zone
->setStartYear(1991);
220 if (zone
->inDaylightTime(marchOne
, status
) ||
221 zone
->inDaylightTime(julyOne
- 1000, status
))
222 errln("FAIL: Start year broken");
224 failure(status
, "TestRuleAPI");
230 TimeZoneTest::findTransition(const TimeZone
& tz
,
231 UDate min
, UDate max
) {
232 UErrorCode ec
= U_ZERO_ERROR
;
234 UBool startsInDST
= tz
.inDaylightTime(min
, ec
);
235 if (failure(ec
, "TimeZone::inDaylightTime")) return;
236 if (tz
.inDaylightTime(max
, ec
) == startsInDST
) {
237 logln("Error: " + tz
.getID(id
) + ".inDaylightTime(" + dateToString(min
) + ") = " + (startsInDST
?"TRUE":"FALSE") +
238 ", inDaylightTime(" + dateToString(max
) + ") = " + (startsInDST
?"TRUE":"FALSE"));
241 if (failure(ec
, "TimeZone::inDaylightTime")) return;
242 while ((max
- min
) > INTERVAL
) {
243 UDate mid
= (min
+ max
) / 2;
244 if (tz
.inDaylightTime(mid
, ec
) == startsInDST
) {
249 if (failure(ec
, "TimeZone::inDaylightTime")) return;
251 min
= 1000.0 * uprv_floor(min
/1000.0);
252 max
= 1000.0 * uprv_floor(max
/1000.0);
253 logln(tz
.getID(id
) + " Before: " + min
/1000 + " = " +
254 dateToString(min
,s
,tz
));
255 logln(tz
.getID(id
) + " After: " + max
/1000 + " = " +
256 dateToString(max
,s
,tz
));
260 TimeZoneTest::testUsingBinarySearch(const TimeZone
& tz
,
261 UDate min
, UDate max
,
262 UDate expectedBoundary
)
264 UErrorCode status
= U_ZERO_ERROR
;
265 UBool startsInDST
= tz
.inDaylightTime(min
, status
);
266 if (failure(status
, "TimeZone::inDaylightTime")) return;
267 if (tz
.inDaylightTime(max
, status
) == startsInDST
) {
268 logln("Error: inDaylightTime(" + dateToString(max
) + ") != " + ((!startsInDST
)?"TRUE":"FALSE"));
271 if (failure(status
, "TimeZone::inDaylightTime")) return;
272 while ((max
- min
) > INTERVAL
) {
273 UDate mid
= (min
+ max
) / 2;
274 if (tz
.inDaylightTime(mid
, status
) == startsInDST
) {
279 if (failure(status
, "TimeZone::inDaylightTime")) return;
281 logln(UnicodeString("Binary Search Before: ") + uprv_floor(0.5 + min
) + " = " + dateToString(min
));
282 logln(UnicodeString("Binary Search After: ") + uprv_floor(0.5 + max
) + " = " + dateToString(max
));
283 UDate mindelta
= expectedBoundary
- min
;
284 UDate maxdelta
= max
- expectedBoundary
;
286 mindelta
<= INTERVAL
&&
288 maxdelta
<= INTERVAL
)
289 logln(UnicodeString("PASS: Expected bdry: ") + expectedBoundary
+ " = " + dateToString(expectedBoundary
));
291 errln(UnicodeString("FAIL: Expected bdry: ") + expectedBoundary
+ " = " + dateToString(expectedBoundary
));
294 const UDate
TimeZoneTest::INTERVAL
= 100;
296 // ---------------------------------------------------------------------------------
298 // -------------------------------------
301 * Test the offset of the PRT timezone.
304 TimeZoneTest::TestPRTOffset()
306 TimeZone
* tz
= TimeZone::createTimeZone("PRT");
308 errln("FAIL: TimeZone(PRT) is null");
311 int32_t expectedHour
= -4;
312 double expectedOffset
= (((double)expectedHour
) * millisPerHour
);
313 double foundOffset
= tz
->getRawOffset();
314 int32_t foundHour
= (int32_t)foundOffset
/ millisPerHour
;
315 if (expectedOffset
!= foundOffset
) {
316 dataerrln("FAIL: Offset for PRT should be %d, found %d", expectedHour
, foundHour
);
318 logln("PASS: Offset for PRT should be %d, found %d", expectedHour
, foundHour
);
324 // -------------------------------------
327 * Regress a specific bug with a sequence of API calls.
330 TimeZoneTest::TestVariousAPI518()
332 UErrorCode status
= U_ZERO_ERROR
;
333 TimeZone
* time_zone
= TimeZone::createTimeZone("PST");
334 UDate d
= date(97, UCAL_APRIL
, 30);
336 logln("The timezone is " + time_zone
->getID(str
));
337 if (!time_zone
->inDaylightTime(d
, status
)) dataerrln("FAIL: inDaylightTime returned FALSE");
338 if (failure(status
, "TimeZone::inDaylightTime", TRUE
)) return;
339 if (!time_zone
->useDaylightTime()) dataerrln("FAIL: useDaylightTime returned FALSE");
340 if (time_zone
->getRawOffset() != - 8 * millisPerHour
) dataerrln("FAIL: getRawOffset returned wrong value");
341 GregorianCalendar
*gc
= new GregorianCalendar(status
);
342 if (U_FAILURE(status
)) { errln("FAIL: Couldn't create GregorianCalendar"); return; }
343 gc
->setTime(d
, status
);
344 if (U_FAILURE(status
)) { errln("FAIL: GregorianCalendar::setTime failed"); return; }
345 if (time_zone
->getOffset(gc
->AD
, gc
->get(UCAL_YEAR
, status
), gc
->get(UCAL_MONTH
, status
),
346 gc
->get(UCAL_DATE
, status
), (uint8_t)gc
->get(UCAL_DAY_OF_WEEK
, status
), 0, status
) != - 7 * millisPerHour
)
347 dataerrln("FAIL: getOffset returned wrong value");
348 if (U_FAILURE(status
)) { errln("FAIL: GregorianCalendar::set failed"); return; }
353 // -------------------------------------
356 * Test the call which retrieves the available IDs.
359 TimeZoneTest::TestGetAvailableIDs913()
361 UErrorCode ec
= U_ZERO_ERROR
;
364 #ifdef U_USE_TIMEZONE_OBSOLETE_2_8
365 // Test legacy API -- remove these tests when the corresponding API goes away (duh)
367 const UnicodeString
** ids
= TimeZone::createAvailableIDs(numIDs
);
368 if (ids
== 0 || numIDs
< 1) {
369 errln("FAIL: createAvailableIDs()");
371 UnicodeString
buf("TimeZone::createAvailableIDs() = { ");
372 for(i
=0; i
<numIDs
; ++i
) {
373 if (i
) buf
.append(", ");
378 // we own the array; the caller owns the contained strings (yuck)
383 ids
= TimeZone::createAvailableIDs(-8*U_MILLIS_PER_HOUR
, numIDs
);
384 if (ids
== 0 || numIDs
< 1) {
385 errln("FAIL: createAvailableIDs(-8:00)");
387 UnicodeString
buf("TimeZone::createAvailableIDs(-8:00) = { ");
388 for(i
=0; i
<numIDs
; ++i
) {
389 if (i
) buf
.append(", ");
394 // we own the array; the caller owns the contained strings (yuck)
398 ids
= TimeZone::createAvailableIDs("US", numIDs
);
399 if (ids
== 0 || numIDs
< 1) {
400 errln("FAIL: createAvailableIDs(US) ids=%d, numIDs=%d", ids
, numIDs
);
402 UnicodeString
buf("TimeZone::createAvailableIDs(US) = { ");
403 for(i
=0; i
<numIDs
; ++i
) {
404 if (i
) buf
.append(", ");
409 // we own the array; the caller owns the contained strings (yuck)
415 UnicodeString
*buf
= new UnicodeString("TimeZone::createEnumeration() = { ");
417 StringEnumeration
* s
= TimeZone::createEnumeration();
419 dataerrln("Unable to create TimeZone enumeration");
422 s_length
= s
->count(ec
);
423 for (i
= 0; i
< s_length
;++i
) {
424 if (i
> 0) *buf
+= ", ";
426 *buf
+= *s
->snext(ec
);
428 *buf
+= UnicodeString(s
->next(NULL
, ec
), "");
432 // replace s with a clone of itself
433 StringEnumeration
*s2
= s
->clone();
434 if(s2
== NULL
|| s_length
!= s2
->count(ec
)) {
435 errln("TimezoneEnumeration.clone() failed");
445 /* Confirm that the following zones can be retrieved: The first
446 * zone, the last zone, and one in-between. This tests the binary
447 * search through the system zone data.
450 int32_t middle
= s_length
/2;
451 for (i
=0; i
<s_length
; ++i
) {
452 const UnicodeString
* id
= s
->snext(ec
);
453 if (i
==0 || i
==middle
|| i
==(s_length
-1)) {
454 TimeZone
*z
= TimeZone::createTimeZone(*id
);
456 errln(UnicodeString("FAIL: createTimeZone(") +
458 } else if (z
->getID(str
) != *id
) {
459 errln(UnicodeString("FAIL: createTimeZone(") +
460 *id
+ ") -> zone " + str
);
462 logln(UnicodeString("OK: createTimeZone(") +
463 *id
+ ") succeeded");
471 *buf
+= "TimeZone::createEnumeration(GMT+01:00) = { ";
473 s
= TimeZone::createEnumeration(1 * U_MILLIS_PER_HOUR
);
474 s_length
= s
->count(ec
);
475 for (i
= 0; i
< s_length
;++i
) {
476 if (i
> 0) *buf
+= ", ";
477 *buf
+= *s
->snext(ec
);
485 *buf
+= "TimeZone::createEnumeration(US) = { ";
487 s
= TimeZone::createEnumeration("US");
488 s_length
= s
->count(ec
);
489 for (i
= 0; i
< s_length
;++i
) {
490 if (i
> 0) *buf
+= ", ";
491 *buf
+= *s
->snext(ec
);
496 TimeZone
*tz
= TimeZone::createTimeZone("PST");
497 if (tz
!= 0) logln("getTimeZone(PST) = " + tz
->getID(str
));
498 else errln("FAIL: getTimeZone(PST) = null");
500 tz
= TimeZone::createTimeZone("America/Los_Angeles");
501 if (tz
!= 0) logln("getTimeZone(America/Los_Angeles) = " + tz
->getID(str
));
502 else errln("FAIL: getTimeZone(PST) = null");
506 tz
= TimeZone::createTimeZone("NON_EXISTENT");
509 errln("FAIL: getTimeZone(NON_EXISTENT) = null");
510 else if (tz
->getID(temp
) != UCAL_UNKNOWN_ZONE_ID
)
511 errln("FAIL: getTimeZone(NON_EXISTENT) = " + temp
);
519 TimeZoneTest::TestGetAvailableIDsNew()
521 UErrorCode ec
= U_ZERO_ERROR
;
522 StringEnumeration
*any
, *canonical
, *canonicalLoc
;
523 StringEnumeration
*any_US
, *canonical_US
, *canonicalLoc_US
;
524 StringEnumeration
*any_W5
, *any_CA_W5
;
525 StringEnumeration
*any_US_E14
;
527 const UnicodeString
*id1
, *id2
;
528 UnicodeString canonicalID
;
533 any
= canonical
= canonicalLoc
= any_US
= canonical_US
= canonicalLoc_US
= any_W5
= any_CA_W5
= any_US_E14
= NULL
;
535 any
= TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY
, NULL
, NULL
, ec
);
537 dataerrln("Failed to create enumration for ANY");
541 canonical
= TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL
, NULL
, NULL
, ec
);
543 errln("Failed to create enumration for CANONICAL");
547 canonicalLoc
= TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL_LOCATION
, NULL
, NULL
, ec
);
549 errln("Failed to create enumration for CANONICALLOC");
553 any_US
= TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY
, "US", NULL
, ec
);
555 errln("Failed to create enumration for ANY_US");
559 canonical_US
= TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL
, "US", NULL
, ec
);
561 errln("Failed to create enumration for CANONICAL_US");
565 canonicalLoc_US
= TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL_LOCATION
, "US", NULL
, ec
);
567 errln("Failed to create enumration for CANONICALLOC_US");
571 rawOffset
= (-5)*60*60*1000;
572 any_W5
= TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY
, NULL
, &rawOffset
, ec
);
574 errln("Failed to create enumration for ANY_W5");
578 any_CA_W5
= TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY
, "CA", &rawOffset
, ec
);
580 errln("Failed to create enumration for ANY_CA_W5");
584 rawOffset
= 14*60*60*1000;
585 any_US_E14
= TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY
, "US", &rawOffset
, ec
);
587 errln("Failed to create enumration for ANY_US_E14");
591 checkContainsAll(any
, "ANY", canonical
, "CANONICAL");
592 checkContainsAll(canonical
, "CANONICAL", canonicalLoc
, "CANONICALLOC");
594 checkContainsAll(any
, "ANY", any_US
, "ANY_US");
595 checkContainsAll(canonical
, "CANONICAL", canonical_US
, "CANONICAL_US");
596 checkContainsAll(canonicalLoc
, "CANONICALLOC", canonicalLoc_US
, "CANONICALLOC_US");
598 checkContainsAll(any_US
, "ANY_US", canonical_US
, "CANONICAL_US");
599 checkContainsAll(canonical_US
, "CANONICAL_US", canonicalLoc_US
, "CANONICALLOC_US");
601 checkContainsAll(any
, "ANY", any_W5
, "ANY_W5");
602 checkContainsAll(any_W5
, "ANY_W5", any_CA_W5
, "ANY_CA_W5");
604 // And ID in any set, but not in canonical set must not be a canonical ID
606 while ((id1
= any
->snext(ec
)) != NULL
) {
608 canonical
->reset(ec
);
609 while ((id2
= canonical
->snext(ec
)) != NULL
) {
619 TimeZone::getCanonicalID(*id1
, canonicalID
, isSystemID
, ec
);
623 if (*id1
== canonicalID
) {
624 errln((UnicodeString
)"FAIL: canonicalID [" + *id1
+ "] is not in CANONICAL");
627 errln((UnicodeString
)"FAIL: ANY contains non-system ID: " + *id1
);
632 errln("Error checking IDs in ANY, but not in CANONICAL");
636 // canonical set must contains only canonical IDs
637 canonical
->reset(ec
);
638 while ((id1
= canonical
->snext(ec
)) != NULL
) {
639 TimeZone::getCanonicalID(*id1
, canonicalID
, isSystemID
, ec
);
643 if (*id1
!= canonicalID
) {
644 errln((UnicodeString
)"FAIL: CANONICAL contains non-canonical ID: " + *id1
);
647 errln((UnicodeString
)"FAILE: CANONICAL contains non-system ID: " + *id1
);
651 errln("Error checking IDs in CANONICAL");
655 // canonicalLoc set must contain only canonical location IDs
656 canonicalLoc
->reset(ec
);
657 while ((id1
= canonicalLoc
->snext(ec
)) != NULL
) {
658 TimeZone::getRegion(*id1
, region
, sizeof(region
), ec
);
662 if (uprv_strcmp(region
, "001") == 0) {
663 errln((UnicodeString
)"FAIL: CANONICALLOC contains non location zone: " + *id1
);
667 errln("Error checking IDs in CANONICALLOC");
671 // any_US must contain only US zones
673 while ((id1
= any_US
->snext(ec
)) != NULL
) {
674 TimeZone::getRegion(*id1
, region
, sizeof(region
), ec
);
678 if (uprv_strcmp(region
, "US") != 0) {
679 errln((UnicodeString
)"FAIL: ANY_US contains non-US zone ID: " + *id1
);
683 errln("Error checking IDs in ANY_US");
687 // any_W5 must contain only GMT-05:00 zones
689 while ((id1
= any_W5
->snext(ec
)) != NULL
) {
690 TimeZone
*tz
= TimeZone::createTimeZone(*id1
);
691 if (tz
->getRawOffset() != (-5)*60*60*1000) {
692 errln((UnicodeString
)"FAIL: ANY_W5 contains a zone whose offset is not -05:00: " + *id1
);
697 errln("Error checking IDs in ANY_W5");
701 // No US zone swith GMT+14:00
702 zoneCount
= any_US_E14
->count(ec
);
704 errln("Error checking IDs in ANY_US_E14");
706 } else if (zoneCount
!= 0) {
707 errln("FAIL: ANY_US_E14 must be empty");
716 delete canonicalLoc_US
;
723 TimeZoneTest::checkContainsAll(StringEnumeration
*s1
, const char *name1
,
724 StringEnumeration
*s2
, const char *name2
)
726 UErrorCode ec
= U_ZERO_ERROR
;
727 const UnicodeString
*id1
, *id2
;
731 while ((id2
= s2
->snext(ec
)) != NULL
) {
734 while ((id1
= s1
->snext(ec
)) != NULL
) {
741 errln((UnicodeString
)"FAIL: " + name1
+ "does not contain "
742 + *id2
+ " in " + name2
);
747 errln((UnicodeString
)"Error checkContainsAll for " + name1
+ " - " + name2
);
752 * NOTE: As of ICU 2.8, this test confirms that the "tz.alias"
753 * file, used to build ICU alias zones, is working. It also
754 * looks at some genuine Olson compatibility IDs. [aliu]
756 * This test is problematic. It should really just confirm that
757 * the list of compatibility zone IDs exist and are somewhat
758 * meaningful (that is, they aren't all aliases of GMT). It goes a
759 * bit further -- it hard-codes expectations about zone behavior,
760 * when in fact zones are redefined quite frequently. ICU's build
761 * process means that it is easy to update ICU to contain the
762 * latest Olson zone data, but if a zone tested here changes, then
763 * this test will fail. I have updated the test for 1999j data,
764 * but further updates will probably be required. Note that some
765 * of the concerts listed below no longer apply -- in particular,
766 * we do NOT overwrite real UNIX zones with 3-letter IDs. There
767 * are two points of overlap as of 1999j: MET and EET. These are
768 * both real UNIX zones, so we just use the official
769 * definition. This test has been updated to reflect this.
772 * Added tests for additional zones and aliases from the icuzones file.
773 * Markus Scherer 2006-nov-06
775 * [srl - from java - 7/5/1998]
777 * Certain short zone IDs, used since 1.1.x, are incorrect.
779 * The worst of these is:
781 * "CAT" (Central African Time) should be GMT+2:00, but instead returns a
782 * zone at GMT-1:00. The zone at GMT-1:00 should be called EGT, CVT, EGST,
783 * or AZOST, depending on which zone is meant, but in no case is it CAT.
785 * Other wrong zone IDs:
787 * ECT (European Central Time) GMT+1:00: ECT is Ecuador Time,
788 * GMT-5:00. European Central time is abbreviated CEST.
790 * SST (Solomon Island Time) GMT+11:00. SST is actually Samoa Standard Time,
791 * GMT-11:00. Solomon Island time is SBT.
793 * NST (New Zealand Time) GMT+12:00. NST is the abbreviation for
794 * Newfoundland Standard Time, GMT-3:30. New Zealanders use NZST.
796 * AST (Alaska Standard Time) GMT-9:00. [This has already been noted in
797 * another bug.] It should be "AKST". AST is Atlantic Standard Time,
800 * PNT (Phoenix Time) GMT-7:00. PNT usually means Pitcairn Time,
801 * GMT-8:30. There is no standard abbreviation for Phoenix time, as distinct
802 * from MST with daylight savings.
804 * In addition to these problems, a number of zones are FAKE. That is, they
805 * don't match what people use in the real world.
809 * EET (should be EEST)
810 * ART (should be EEST)
811 * MET (should be IRST)
812 * NET (should be AMST)
813 * PLT (should be PKT)
814 * BST (should be BDT)
815 * VST (should be ICT)
816 * CTT (should be CST) +
817 * ACT (should be CST) +
818 * AET (should be EST) +
819 * MIT (should be WST) +
820 * IET (should be EST) +
821 * PRT (should be AST) +
822 * CNT (should be NST)
823 * AGT (should be ARST)
824 * BET (should be EST) +
826 * + A zone with the correct name already exists and means something
827 * else. E.g., EST usually indicates the US Eastern zone, so it cannot be
828 * used for Brazil (BET).
830 void TimeZoneTest::TestShortZoneIDs()
833 // Create a small struct to hold the array
842 {"HST", -600, FALSE
}, // Olson northamerica -10:00
843 {"AST", -540, TRUE
}, // ICU Link - America/Anchorage
844 {"PST", -480, TRUE
}, // ICU Link - America/Los_Angeles
845 {"PNT", -420, FALSE
}, // ICU Link - America/Phoenix
846 {"MST", -420, FALSE
}, // updated Aug 2003 aliu
847 {"CST", -360, TRUE
}, // Olson northamerica -7:00
848 {"IET", -300, TRUE
}, // ICU Link - America/Indiana/Indianapolis
849 {"EST", -300, FALSE
}, // Olson northamerica -5:00
850 {"PRT", -240, FALSE
}, // ICU Link - America/Puerto_Rico
851 {"CNT", -210, TRUE
}, // ICU Link - America/St_Johns
852 {"AGT", -180, FALSE
}, // ICU Link - America/Argentina/Buenos_Aires
853 {"BET", -180, TRUE
}, // ICU Link - America/Sao_Paulo
854 {"GMT", 0, FALSE
}, // Olson etcetera Link - Etc/GMT
855 {"UTC", 0, FALSE
}, // Olson etcetera 0
856 {"ECT", 60, TRUE
}, // ICU Link - Europe/Paris
857 {"MET", 60, TRUE
}, // Olson europe 1:00 C-Eur
858 {"CAT", 120, FALSE
}, // ICU Link - Africa/Maputo
859 {"ART", 120, TRUE
}, // ICU Link - Africa/Cairo
860 {"EET", 120, TRUE
}, // Olson europe 2:00 EU
861 {"EAT", 180, FALSE
}, // ICU Link - Africa/Addis_Ababa
862 {"NET", 240, FALSE
}, // ICU Link - Asia/Yerevan
863 {"PLT", 300, FALSE
}, // ICU Link - Asia/Karachi
864 {"IST", 330, FALSE
}, // ICU Link - Asia/Kolkata
865 {"BST", 360, FALSE
}, // ICU Link - Asia/Dhaka
866 {"VST", 420, FALSE
}, // ICU Link - Asia/Ho_Chi_Minh
867 {"CTT", 480, FALSE
}, // ICU Link - Asia/Shanghai
868 {"JST", 540, FALSE
}, // ICU Link - Asia/Tokyo
869 {"ACT", 570, FALSE
}, // ICU Link - Australia/Darwin
870 {"AET", 600, TRUE
}, // ICU Link - Australia/Sydney
871 {"SST", 660, FALSE
}, // ICU Link - Pacific/Guadalcanal
872 {"NST", 720, TRUE
}, // ICU Link - Pacific/Auckland
873 {"MIT", 780, TRUE
}, // ICU Link - Pacific/Apia
875 {"Etc/Unknown", 0, FALSE
}, // CLDR
877 {"SystemV/AST4ADT", -240, TRUE
},
878 {"SystemV/EST5EDT", -300, TRUE
},
879 {"SystemV/CST6CDT", -360, TRUE
},
880 {"SystemV/MST7MDT", -420, TRUE
},
881 {"SystemV/PST8PDT", -480, TRUE
},
882 {"SystemV/YST9YDT", -540, TRUE
},
883 {"SystemV/AST4", -240, FALSE
},
884 {"SystemV/EST5", -300, FALSE
},
885 {"SystemV/CST6", -360, FALSE
},
886 {"SystemV/MST7", -420, FALSE
},
887 {"SystemV/PST8", -480, FALSE
},
888 {"SystemV/YST9", -540, FALSE
},
889 {"SystemV/HST10", -600, FALSE
},
894 for(i
=0;kReferenceList
[i
].id
[0];i
++) {
895 UnicodeString
itsID(kReferenceList
[i
].id
);
898 TimeZone
*tz
= TimeZone::createTimeZone(itsID
);
899 if (!tz
|| (kReferenceList
[i
].offset
!= 0 && *tz
== *TimeZone::getGMT())) {
900 errln("FAIL: Time Zone " + itsID
+ " does not exist!");
904 // Check daylight usage.
905 UBool usesDaylight
= tz
->useDaylightTime();
906 if (usesDaylight
!= kReferenceList
[i
].daylight
) {
907 if (!isDevelopmentBuild
) {
908 logln("Warning: Time Zone " + itsID
+ " use daylight is " +
909 (usesDaylight
?"TRUE":"FALSE") +
910 " but it should be " +
911 ((kReferenceList
[i
].daylight
)?"TRUE":"FALSE"));
913 dataerrln("FAIL: Time Zone " + itsID
+ " use daylight is " +
914 (usesDaylight
?"TRUE":"FALSE") +
915 " but it should be " +
916 ((kReferenceList
[i
].daylight
)?"TRUE":"FALSE"));
922 int32_t offsetInMinutes
= tz
->getRawOffset()/60000;
923 if (offsetInMinutes
!= kReferenceList
[i
].offset
) {
924 if (!isDevelopmentBuild
) {
925 logln("FAIL: Time Zone " + itsID
+ " raw offset is " +
927 " but it should be " + kReferenceList
[i
].offset
);
929 dataerrln("FAIL: Time Zone " + itsID
+ " raw offset is " +
931 " but it should be " + kReferenceList
[i
].offset
);
937 logln("OK: " + itsID
+
938 " useDaylightTime() & getRawOffset() as expected");
944 // OK now test compat
945 logln("Testing for compatibility zones");
947 const char* compatibilityMap
[] = {
948 // This list is copied from tz.alias. If tz.alias
949 // changes, this list must be updated. Current as of Mar 2007
950 "ACT", "Australia/Darwin",
951 "AET", "Australia/Sydney",
952 "AGT", "America/Buenos_Aires",
953 "ART", "Africa/Cairo",
954 "AST", "America/Anchorage",
955 "BET", "America/Sao_Paulo",
956 "BST", "Asia/Dhaka", // # spelling changed in 2000h; was Asia/Dacca
957 "CAT", "Africa/Maputo",
958 "CNT", "America/St_Johns",
959 "CST", "America/Chicago",
960 "CTT", "Asia/Shanghai",
961 "EAT", "Africa/Addis_Ababa",
962 "ECT", "Europe/Paris",
963 // EET Europe/Istanbul # EET is a standard UNIX zone
964 // "EST", "America/New_York", # Defined as -05:00
965 // "HST", "Pacific/Honolulu", # Defined as -10:00
966 "IET", "America/Indianapolis",
967 "IST", "Asia/Calcutta",
969 // MET Asia/Tehran # MET is a standard UNIX zone
970 "MIT", "Pacific/Apia",
971 // "MST", "America/Denver", # Defined as -07:00
972 "NET", "Asia/Yerevan",
973 "NST", "Pacific/Auckland",
974 "PLT", "Asia/Karachi",
975 "PNT", "America/Phoenix",
976 "PRT", "America/Puerto_Rico",
977 "PST", "America/Los_Angeles",
978 "SST", "Pacific/Guadalcanal",
980 "VST", "Asia/Saigon",
984 for (i
=0;*compatibilityMap
[i
];i
+=2) {
987 const char *zone1
= compatibilityMap
[i
];
988 const char *zone2
= compatibilityMap
[i
+1];
990 TimeZone
*tz1
= TimeZone::createTimeZone(zone1
);
991 TimeZone
*tz2
= TimeZone::createTimeZone(zone2
);
994 errln(UnicodeString("FAIL: Could not find short ID zone ") + zone1
);
997 errln(UnicodeString("FAIL: Could not find long ID zone ") + zone2
);
1001 // make NAME same so comparison will only look at the rest
1002 tz2
->setID(tz1
->getID(itsID
));
1005 errln("FAIL: " + UnicodeString(zone1
) +
1006 " != " + UnicodeString(zone2
));
1008 logln("OK: " + UnicodeString(zone1
) +
1009 " == " + UnicodeString(zone2
));
1020 * Utility function for TestCustomParse
1022 UnicodeString
& TimeZoneTest::formatOffset(int32_t offset
, UnicodeString
&rv
) {
1024 UChar sign
= 0x002B;
1030 int32_t s
= offset
% 60;
1032 int32_t m
= offset
% 60;
1033 int32_t h
= offset
/ 60;
1035 rv
+= (UChar
)(sign
);
1037 rv
+= (UChar
)(0x0030 + (h
/10));
1039 rv
+= (UChar
)0x0030;
1041 rv
+= (UChar
)(0x0030 + (h%10
));
1043 rv
+= (UChar
)0x003A; /* ':' */
1045 rv
+= (UChar
)(0x0030 + (m
/10));
1047 rv
+= (UChar
)0x0030;
1049 rv
+= (UChar
)(0x0030 + (m%10
));
1052 rv
+= (UChar
)0x003A; /* ':' */
1054 rv
+= (UChar
)(0x0030 + (s
/10));
1056 rv
+= (UChar
)0x0030;
1058 rv
+= (UChar
)(0x0030 + (s%10
));
1064 * Utility function for TestCustomParse, generating time zone ID
1065 * string for the give offset.
1067 UnicodeString
& TimeZoneTest::formatTZID(int32_t offset
, UnicodeString
&rv
) {
1069 UChar sign
= 0x002B;
1075 int32_t s
= offset
% 60;
1077 int32_t m
= offset
% 60;
1078 int32_t h
= offset
/ 60;
1081 rv
+= (UChar
)(sign
);
1083 rv
+= (UChar
)(0x0030 + (h
/10));
1085 rv
+= (UChar
)0x0030;
1087 rv
+= (UChar
)(0x0030 + (h%10
));
1088 rv
+= (UChar
)0x003A;
1090 rv
+= (UChar
)(0x0030 + (m
/10));
1092 rv
+= (UChar
)0x0030;
1094 rv
+= (UChar
)(0x0030 + (m%10
));
1097 rv
+= (UChar
)0x003A;
1099 rv
+= (UChar
)(0x0030 + (s
/10));
1101 rv
+= (UChar
)0x0030;
1103 rv
+= (UChar
)(0x0030 + (s%10
));
1109 * As part of the VM fix (see CCC approved RFE 4028006, bug
1110 * 4044013), TimeZone.getTimeZone() has been modified to recognize
1111 * generic IDs of the form GMT[+-]hh:mm, GMT[+-]hhmm, and
1112 * GMT[+-]hh. Test this behavior here.
1116 void TimeZoneTest::TestCustomParse()
1119 const int32_t kUnparseable
= 604800; // the number of seconds in a week. More than any offset should be.
1123 const char *customId
;
1124 int32_t expectedOffset
;
1128 // ID Expected offset in seconds
1129 {"GMT", kUnparseable
}, //Isn't custom. [returns normal GMT]
1130 {"GMT-YOUR.AD.HERE", kUnparseable
},
1131 {"GMT0", kUnparseable
},
1133 {"GMT+1", (1*60*60)},
1134 {"GMT-0030", (-30*60)},
1135 {"GMT+15:99", kUnparseable
},
1136 {"GMT+", kUnparseable
},
1137 {"GMT-", kUnparseable
},
1138 {"GMT+0:", kUnparseable
},
1139 {"GMT-:", kUnparseable
},
1140 {"GMT-YOUR.AD.HERE", kUnparseable
},
1141 {"GMT+0010", (10*60)}, // Interpret this as 00:10
1142 {"GMT-10", (-10*60*60)},
1143 {"GMT+30", kUnparseable
},
1144 {"GMT-3:30", (-(3*60+30)*60)},
1145 {"GMT-230", (-(2*60+30)*60)},
1146 {"GMT+05:13:05", ((5*60+13)*60+5)},
1147 {"GMT-71023", (-((7*60+10)*60+23))},
1148 {"GMT+01:23:45:67", kUnparseable
},
1149 {"GMT+01:234", kUnparseable
},
1150 {"GMT-2:31:123", kUnparseable
},
1151 {"GMT+3:75", kUnparseable
},
1152 {"GMT-01010101", kUnparseable
},
1156 for (i
=0; kData
[i
].customId
!= 0; i
++) {
1157 UnicodeString
id(kData
[i
].customId
);
1158 int32_t exp
= kData
[i
].expectedOffset
;
1159 TimeZone
*zone
= TimeZone::createTimeZone(id
);
1160 UnicodeString itsID
, temp
;
1162 if (dynamic_cast<OlsonTimeZone
*>(zone
) != NULL
) {
1163 logln(id
+ " -> Olson time zone");
1166 int32_t ioffset
= zone
->getRawOffset()/1000;
1167 UnicodeString offset
, expectedID
;
1168 formatOffset(ioffset
, offset
);
1169 formatTZID(ioffset
, expectedID
);
1170 logln(id
+ " -> " + itsID
+ " " + offset
);
1171 if (exp
== kUnparseable
&& itsID
!= UCAL_UNKNOWN_ZONE_ID
) {
1172 errln("Expected parse failure for " + id
+
1173 ", got offset of " + offset
+
1176 // JDK 1.3 creates custom zones with the ID "Custom"
1177 // JDK 1.4 creates custom zones with IDs of the form "GMT+02:00"
1178 // ICU creates custom zones with IDs of the form "GMT+02:00"
1179 else if (exp
!= kUnparseable
&& (ioffset
!= exp
|| itsID
!= expectedID
)) {
1180 dataerrln("Expected offset of " + formatOffset(exp
, temp
) +
1181 ", id " + expectedID
+
1183 ", got offset of " + offset
+
1192 TimeZoneTest::TestAliasedNames()
1198 /* Generated by org.unicode.cldr.tool.CountItems */
1200 /* zoneID, canonical zoneID */
1201 {"Africa/Timbuktu", "Africa/Bamako"},
1202 {"America/Argentina/Buenos_Aires", "America/Buenos_Aires"},
1203 {"America/Argentina/Catamarca", "America/Catamarca"},
1204 {"America/Argentina/ComodRivadavia", "America/Catamarca"},
1205 {"America/Argentina/Cordoba", "America/Cordoba"},
1206 {"America/Argentina/Jujuy", "America/Jujuy"},
1207 {"America/Argentina/Mendoza", "America/Mendoza"},
1208 {"America/Atka", "America/Adak"},
1209 {"America/Ensenada", "America/Tijuana"},
1210 {"America/Fort_Wayne", "America/Indiana/Indianapolis"},
1211 {"America/Indianapolis", "America/Indiana/Indianapolis"},
1212 {"America/Knox_IN", "America/Indiana/Knox"},
1213 {"America/Louisville", "America/Kentucky/Louisville"},
1214 {"America/Porto_Acre", "America/Rio_Branco"},
1215 {"America/Rosario", "America/Cordoba"},
1216 {"America/Virgin", "America/St_Thomas"},
1217 {"Asia/Ashkhabad", "Asia/Ashgabat"},
1218 {"Asia/Chungking", "Asia/Chongqing"},
1219 {"Asia/Dacca", "Asia/Dhaka"},
1220 {"Asia/Istanbul", "Europe/Istanbul"},
1221 {"Asia/Macao", "Asia/Macau"},
1222 {"Asia/Tel_Aviv", "Asia/Jerusalem"},
1223 {"Asia/Thimbu", "Asia/Thimphu"},
1224 {"Asia/Ujung_Pandang", "Asia/Makassar"},
1225 {"Asia/Ulan_Bator", "Asia/Ulaanbaatar"},
1226 {"Australia/ACT", "Australia/Sydney"},
1227 {"Australia/Canberra", "Australia/Sydney"},
1228 {"Australia/LHI", "Australia/Lord_Howe"},
1229 {"Australia/NSW", "Australia/Sydney"},
1230 {"Australia/North", "Australia/Darwin"},
1231 {"Australia/Queensland", "Australia/Brisbane"},
1232 {"Australia/South", "Australia/Adelaide"},
1233 {"Australia/Tasmania", "Australia/Hobart"},
1234 {"Australia/Victoria", "Australia/Melbourne"},
1235 {"Australia/West", "Australia/Perth"},
1236 {"Australia/Yancowinna", "Australia/Broken_Hill"},
1237 {"Brazil/Acre", "America/Rio_Branco"},
1238 {"Brazil/DeNoronha", "America/Noronha"},
1239 {"Brazil/East", "America/Sao_Paulo"},
1240 {"Brazil/West", "America/Manaus"},
1241 {"Canada/Atlantic", "America/Halifax"},
1242 {"Canada/Central", "America/Winnipeg"},
1243 {"Canada/East-Saskatchewan", "America/Regina"},
1244 {"Canada/Eastern", "America/Toronto"},
1245 {"Canada/Mountain", "America/Edmonton"},
1246 {"Canada/Newfoundland", "America/St_Johns"},
1247 {"Canada/Pacific", "America/Vancouver"},
1248 {"Canada/Saskatchewan", "America/Regina"},
1249 {"Canada/Yukon", "America/Whitehorse"},
1250 {"Chile/Continental", "America/Santiago"},
1251 {"Chile/EasterIsland", "Pacific/Easter"},
1252 {"Cuba", "America/Havana"},
1253 {"Egypt", "Africa/Cairo"},
1254 {"Eire", "Europe/Dublin"},
1255 {"Etc/GMT+0", "Etc/GMT"},
1256 {"Etc/GMT-0", "Etc/GMT"},
1257 {"Etc/GMT0", "Etc/GMT"},
1258 {"Etc/Greenwich", "Etc/GMT"},
1259 {"Etc/UCT", "Etc/GMT"},
1260 {"Etc/UTC", "Etc/GMT"},
1261 {"Etc/Universal", "Etc/GMT"},
1262 {"Etc/Zulu", "Etc/GMT"},
1263 {"Europe/Belfast", "Europe/London"},
1264 {"Europe/Nicosia", "Asia/Nicosia"},
1265 {"Europe/Tiraspol", "Europe/Chisinau"},
1266 {"GB", "Europe/London"},
1267 {"GB-Eire", "Europe/London"},
1269 {"GMT+0", "Etc/GMT"},
1270 {"GMT-0", "Etc/GMT"},
1271 {"GMT0", "Etc/GMT"},
1272 {"Greenwich", "Etc/GMT"},
1273 {"Hongkong", "Asia/Hong_Kong"},
1274 {"Iceland", "Atlantic/Reykjavik"},
1275 {"Iran", "Asia/Tehran"},
1276 {"Israel", "Asia/Jerusalem"},
1277 {"Jamaica", "America/Jamaica"},
1278 {"Japan", "Asia/Tokyo"},
1279 {"Kwajalein", "Pacific/Kwajalein"},
1280 {"Libya", "Africa/Tripoli"},
1281 {"Mexico/BajaNorte", "America/Tijuana"},
1282 {"Mexico/BajaSur", "America/Mazatlan"},
1283 {"Mexico/General", "America/Mexico_City"},
1284 {"NZ", "Pacific/Auckland"},
1285 {"NZ-CHAT", "Pacific/Chatham"},
1286 {"Navajo", "America/Shiprock"},
1287 {"PRC", "Asia/Shanghai"},
1288 {"Pacific/Samoa", "Pacific/Pago_Pago"},
1289 {"Pacific/Yap", "Pacific/Truk"},
1290 {"Poland", "Europe/Warsaw"},
1291 {"Portugal", "Europe/Lisbon"},
1292 {"ROC", "Asia/Taipei"},
1293 {"ROK", "Asia/Seoul"},
1294 {"Singapore", "Asia/Singapore"},
1295 {"Turkey", "Europe/Istanbul"},
1297 {"US/Alaska", "America/Anchorage"},
1298 {"US/Aleutian", "America/Adak"},
1299 {"US/Arizona", "America/Phoenix"},
1300 {"US/Central", "America/Chicago"},
1301 {"US/East-Indiana", "America/Indiana/Indianapolis"},
1302 {"US/Eastern", "America/New_York"},
1303 {"US/Hawaii", "Pacific/Honolulu"},
1304 {"US/Indiana-Starke", "America/Indiana/Knox"},
1305 {"US/Michigan", "America/Detroit"},
1306 {"US/Mountain", "America/Denver"},
1307 {"US/Pacific", "America/Los_Angeles"},
1308 {"US/Pacific-New", "America/Los_Angeles"},
1309 {"US/Samoa", "Pacific/Pago_Pago"},
1311 {"Universal", "Etc/GMT"},
1312 {"W-SU", "Europe/Moscow"},
1313 {"Zulu", "Etc/GMT"},
1318 TimeZone::EDisplayType styles
[] = { TimeZone::SHORT
, TimeZone::LONG
};
1319 UBool useDst
[] = { FALSE
, TRUE
};
1320 int32_t noLoc
= uloc_countAvailable();
1322 int32_t i
, j
, k
, loc
;
1323 UnicodeString fromName
, toName
;
1324 TimeZone
*from
= NULL
, *to
= NULL
;
1325 for(i
= 0; i
< (int32_t)(sizeof(kData
)/sizeof(kData
[0])); i
++) {
1326 from
= TimeZone::createTimeZone(kData
[i
].from
);
1327 to
= TimeZone::createTimeZone(kData
[i
].to
);
1328 if(!from
->hasSameRules(*to
)) {
1329 errln("different at %i\n", i
);
1332 for(loc
= 0; loc
< noLoc
; loc
++) {
1333 const char* locale
= uloc_getAvailable(loc
);
1334 for(j
= 0; j
< (int32_t)(sizeof(styles
)/sizeof(styles
[0])); j
++) {
1335 for(k
= 0; k
< (int32_t)(sizeof(useDst
)/sizeof(useDst
[0])); k
++) {
1338 from
->getDisplayName(useDst
[k
], styles
[j
],locale
, fromName
);
1339 to
->getDisplayName(useDst
[k
], styles
[j
], locale
, toName
);
1340 if(fromName
.compare(toName
) != 0) {
1341 errln("Fail: Expected "+toName
+" but got " + prettify(fromName
)
1342 + " for locale: " + locale
+ " index: "+ loc
1343 + " to id "+ kData
[i
].to
1344 + " from id " + kData
[i
].from
);
1352 from
->getDisplayName(fromName
);
1353 to
->getDisplayName(toName
);
1354 if(fromName
.compare(toName
) != 0) {
1355 errln("Fail: Expected "+toName
+" but got " + fromName
);
1364 * Test the basic functionality of the getDisplayName() API.
1369 * See also API change request A41.
1371 * 4/21/98 - make smarter, so the test works if the ext resources
1372 * are present or not.
1375 TimeZoneTest::TestDisplayName()
1377 UErrorCode status
= U_ZERO_ERROR
;
1379 TimeZone
*zone
= TimeZone::createTimeZone("PST");
1381 zone
->getDisplayName(Locale::getEnglish(), name
);
1382 logln("PST->" + name
);
1383 if (name
.compare("Pacific Standard Time") != 0)
1384 dataerrln("Fail: Expected \"Pacific Standard Time\" but got " + name
);
1386 //*****************************************************************
1387 // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES
1388 // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES
1389 // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES
1390 //*****************************************************************
1394 TimeZone::EDisplayType style
;
1397 {FALSE
, TimeZone::SHORT
, "PST"},
1398 {TRUE
, TimeZone::SHORT
, "PDT"},
1399 {FALSE
, TimeZone::LONG
, "Pacific Standard Time"},
1400 {TRUE
, TimeZone::LONG
, "Pacific Daylight Time"},
1402 {FALSE
, TimeZone::SHORT_GENERIC
, "PT"},
1403 {TRUE
, TimeZone::SHORT_GENERIC
, "PT"},
1404 {FALSE
, TimeZone::LONG_GENERIC
, "Pacific Time"},
1405 {TRUE
, TimeZone::LONG_GENERIC
, "Pacific Time"},
1407 {FALSE
, TimeZone::SHORT_GMT
, "-0800"},
1408 {TRUE
, TimeZone::SHORT_GMT
, "-0700"},
1409 {FALSE
, TimeZone::LONG_GMT
, "GMT-08:00"},
1410 {TRUE
, TimeZone::LONG_GMT
, "GMT-07:00"},
1412 {FALSE
, TimeZone::SHORT_COMMONLY_USED
, "PST"},
1413 {TRUE
, TimeZone::SHORT_COMMONLY_USED
, "PDT"},
1414 {FALSE
, TimeZone::GENERIC_LOCATION
, "Los Angeles Time"},
1415 {TRUE
, TimeZone::GENERIC_LOCATION
, "Los Angeles Time"},
1417 {FALSE
, TimeZone::LONG
, ""}
1420 for (i
=0; kData
[i
].expect
[0] != '\0'; i
++)
1423 name
= zone
->getDisplayName(kData
[i
].useDst
,
1425 Locale::getEnglish(), name
);
1426 if (name
.compare(kData
[i
].expect
) != 0)
1427 dataerrln("Fail: Expected " + UnicodeString(kData
[i
].expect
) + "; got " + name
);
1428 logln("PST [with options]->" + name
);
1430 for (i
=0; kData
[i
].expect
[0] != '\0'; i
++)
1433 name
= zone
->getDisplayName(kData
[i
].useDst
,
1434 kData
[i
].style
, name
);
1435 if (name
.compare(kData
[i
].expect
) != 0)
1436 dataerrln("Fail: Expected " + UnicodeString(kData
[i
].expect
) + "; got " + name
);
1437 logln("PST [with options]->" + name
);
1441 // Make sure that we don't display the DST name by constructing a fake
1442 // PST zone that has DST all year long.
1443 SimpleTimeZone
*zone2
= new SimpleTimeZone(0, "PST");
1445 zone2
->setStartRule(UCAL_JANUARY
, 1, 0, 0, status
);
1446 zone2
->setEndRule(UCAL_DECEMBER
, 31, 0, 0, status
);
1448 UnicodeString inDaylight
;
1449 if (zone2
->inDaylightTime(UDate(0), status
)) {
1450 inDaylight
= UnicodeString("TRUE");
1452 inDaylight
= UnicodeString("FALSE");
1454 logln(UnicodeString("Modified PST inDaylightTime->") + inDaylight
);
1455 if(U_FAILURE(status
))
1457 dataerrln("Some sort of error..." + UnicodeString(u_errorName(status
))); // REVISIT
1460 name
= zone2
->getDisplayName(Locale::getEnglish(),name
);
1461 logln("Modified PST->" + name
);
1462 if (name
.compare("Pacific Standard Time") != 0)
1463 dataerrln("Fail: Expected \"Pacific Standard Time\"");
1465 // Make sure we get the default display format for Locales
1466 // with no display name data.
1467 Locale
mt_MT("mt_MT");
1469 name
= zone
->getDisplayName(mt_MT
,name
);
1470 //*****************************************************************
1471 // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES
1472 // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES
1473 // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES
1474 //*****************************************************************
1475 logln("PST(mt_MT)->" + name
);
1477 // *** REVISIT SRL how in the world do I check this? looks java specific.
1478 // Now be smart -- check to see if zh resource is even present.
1479 // If not, we expect the en fallback behavior.
1480 ResourceBundle
enRB(NULL
,
1481 Locale::getEnglish(), status
);
1482 if(U_FAILURE(status
))
1483 dataerrln("Couldn't get ResourceBundle for en - %s", u_errorName(status
));
1485 ResourceBundle
mtRB(NULL
,
1487 //if(U_FAILURE(status))
1488 // errln("Couldn't get ResourceBundle for mt_MT");
1490 UBool noZH
= U_FAILURE(status
);
1493 logln("Warning: Not testing the mt_MT behavior because resource is absent");
1494 if (name
!= "Pacific Standard Time")
1495 dataerrln("Fail: Expected Pacific Standard Time");
1499 if (name
.compare("GMT-08:00") &&
1500 name
.compare("GMT-8:00") &&
1501 name
.compare("GMT-0800") &&
1502 name
.compare("GMT-800")) {
1503 dataerrln(UnicodeString("Fail: Expected GMT-08:00 or something similar for PST in mt_MT but got ") + name
);
1504 dataerrln("************************************************************");
1505 dataerrln("THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED");
1506 dataerrln("************************************************************");
1509 // Now try a non-existent zone
1511 zone2
= new SimpleTimeZone(90*60*1000, "xyzzy");
1513 name
= zone2
->getDisplayName(Locale::getEnglish(),name
);
1514 logln("GMT+90min->" + name
);
1515 if (name
.compare("GMT+01:30") &&
1516 name
.compare("GMT+1:30") &&
1517 name
.compare("GMT+0130") &&
1518 name
.compare("GMT+130"))
1519 dataerrln("Fail: Expected GMT+01:30 or something similar");
1521 zone2
->getDisplayName(name
);
1522 logln("GMT+90min->" + name
);
1523 if (name
.compare("GMT+01:30") &&
1524 name
.compare("GMT+1:30") &&
1525 name
.compare("GMT+0130") &&
1526 name
.compare("GMT+130"))
1527 dataerrln("Fail: Expected GMT+01:30 or something similar");
1537 TimeZoneTest::TestDSTSavings()
1539 UErrorCode status
= U_ZERO_ERROR
;
1540 // It might be better to find a way to integrate this test into the main TimeZone
1541 // tests above, but I don't have time to figure out how to do this (or if it's
1542 // even really a good idea). Let's consider that a future. --rtg 1/27/98
1543 SimpleTimeZone
*tz
= new SimpleTimeZone(-5 * U_MILLIS_PER_HOUR
, "dstSavingsTest",
1544 UCAL_MARCH
, 1, 0, 0, UCAL_SEPTEMBER
, 1, 0, 0,
1545 (int32_t)(0.5 * U_MILLIS_PER_HOUR
), status
);
1546 if(U_FAILURE(status
))
1547 errln("couldn't create TimeZone");
1549 if (tz
->getRawOffset() != -5 * U_MILLIS_PER_HOUR
)
1550 errln(UnicodeString("Got back a raw offset of ") + (tz
->getRawOffset() / U_MILLIS_PER_HOUR
) +
1551 " hours instead of -5 hours.");
1552 if (!tz
->useDaylightTime())
1553 errln("Test time zone should use DST but claims it doesn't.");
1554 if (tz
->getDSTSavings() != 0.5 * U_MILLIS_PER_HOUR
)
1555 errln(UnicodeString("Set DST offset to 0.5 hour, but got back ") + (tz
->getDSTSavings() /
1556 U_MILLIS_PER_HOUR
) + " hours instead.");
1558 int32_t offset
= tz
->getOffset(GregorianCalendar::AD
, 1998, UCAL_JANUARY
, 1,
1559 UCAL_THURSDAY
, 10 * U_MILLIS_PER_HOUR
,status
);
1560 if (offset
!= -5 * U_MILLIS_PER_HOUR
)
1561 errln(UnicodeString("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got ")
1562 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1564 offset
= tz
->getOffset(GregorianCalendar::AD
, 1998, UCAL_JUNE
, 1, UCAL_MONDAY
,
1565 10 * U_MILLIS_PER_HOUR
,status
);
1566 if (offset
!= -4.5 * U_MILLIS_PER_HOUR
)
1567 errln(UnicodeString("The offset for 10 AM, 6/1/98 should have been -4.5 hours, but we got ")
1568 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1570 tz
->setDSTSavings(U_MILLIS_PER_HOUR
, status
);
1571 offset
= tz
->getOffset(GregorianCalendar::AD
, 1998, UCAL_JANUARY
, 1,
1572 UCAL_THURSDAY
, 10 * U_MILLIS_PER_HOUR
,status
);
1573 if (offset
!= -5 * U_MILLIS_PER_HOUR
)
1574 errln(UnicodeString("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got ")
1575 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1577 offset
= tz
->getOffset(GregorianCalendar::AD
, 1998, UCAL_JUNE
, 1, UCAL_MONDAY
,
1578 10 * U_MILLIS_PER_HOUR
,status
);
1579 if (offset
!= -4 * U_MILLIS_PER_HOUR
)
1580 errln(UnicodeString("The offset for 10 AM, 6/1/98 (with a 1-hour DST offset) should have been -4 hours, but we got ")
1581 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1590 TimeZoneTest::TestAlternateRules()
1592 // Like TestDSTSavings, this test should probably be integrated somehow with the main
1593 // test at the top of this class, but I didn't have time to figure out how to do that.
1596 SimpleTimeZone
tz(-5 * U_MILLIS_PER_HOUR
, "alternateRuleTest");
1598 // test the day-of-month API
1599 UErrorCode status
= U_ZERO_ERROR
;
1600 tz
.setStartRule(UCAL_MARCH
, 10, 12 * U_MILLIS_PER_HOUR
, status
);
1601 if(U_FAILURE(status
))
1602 errln("tz.setStartRule failed");
1603 tz
.setEndRule(UCAL_OCTOBER
, 20, 12 * U_MILLIS_PER_HOUR
, status
);
1604 if(U_FAILURE(status
))
1605 errln("tz.setStartRule failed");
1607 int32_t offset
= tz
.getOffset(GregorianCalendar::AD
, 1998, UCAL_MARCH
, 5,
1608 UCAL_THURSDAY
, 10 * U_MILLIS_PER_HOUR
,status
);
1609 if (offset
!= -5 * U_MILLIS_PER_HOUR
)
1610 errln(UnicodeString("The offset for 10AM, 3/5/98 should have been -5 hours, but we got ")
1611 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1613 offset
= tz
.getOffset(GregorianCalendar::AD
, 1998, UCAL_MARCH
, 15,
1614 UCAL_SUNDAY
, 10 * millisPerHour
,status
);
1615 if (offset
!= -4 * U_MILLIS_PER_HOUR
)
1616 errln(UnicodeString("The offset for 10AM, 3/15/98 should have been -4 hours, but we got ")
1617 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1619 offset
= tz
.getOffset(GregorianCalendar::AD
, 1998, UCAL_OCTOBER
, 15,
1620 UCAL_THURSDAY
, 10 * millisPerHour
,status
);
1621 if (offset
!= -4 * U_MILLIS_PER_HOUR
)
1622 errln(UnicodeString("The offset for 10AM, 10/15/98 should have been -4 hours, but we got ") + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1624 offset
= tz
.getOffset(GregorianCalendar::AD
, 1998, UCAL_OCTOBER
, 25,
1625 UCAL_SUNDAY
, 10 * millisPerHour
,status
);
1626 if (offset
!= -5 * U_MILLIS_PER_HOUR
)
1627 errln(UnicodeString("The offset for 10AM, 10/25/98 should have been -5 hours, but we got ")
1628 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1630 // test the day-of-week-after-day-in-month API
1631 tz
.setStartRule(UCAL_MARCH
, 10, UCAL_FRIDAY
, 12 * millisPerHour
, TRUE
, status
);
1632 if(U_FAILURE(status
))
1633 errln("tz.setStartRule failed");
1634 tz
.setEndRule(UCAL_OCTOBER
, 20, UCAL_FRIDAY
, 12 * millisPerHour
, FALSE
, status
);
1635 if(U_FAILURE(status
))
1636 errln("tz.setStartRule failed");
1638 offset
= tz
.getOffset(GregorianCalendar::AD
, 1998, UCAL_MARCH
, 11,
1639 UCAL_WEDNESDAY
, 10 * millisPerHour
,status
);
1640 if (offset
!= -5 * U_MILLIS_PER_HOUR
)
1641 errln(UnicodeString("The offset for 10AM, 3/11/98 should have been -5 hours, but we got ")
1642 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1644 offset
= tz
.getOffset(GregorianCalendar::AD
, 1998, UCAL_MARCH
, 14,
1645 UCAL_SATURDAY
, 10 * millisPerHour
,status
);
1646 if (offset
!= -4 * U_MILLIS_PER_HOUR
)
1647 errln(UnicodeString("The offset for 10AM, 3/14/98 should have been -4 hours, but we got ")
1648 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1650 offset
= tz
.getOffset(GregorianCalendar::AD
, 1998, UCAL_OCTOBER
, 15,
1651 UCAL_THURSDAY
, 10 * millisPerHour
,status
);
1652 if (offset
!= -4 * U_MILLIS_PER_HOUR
)
1653 errln(UnicodeString("The offset for 10AM, 10/15/98 should have been -4 hours, but we got ")
1654 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1656 offset
= tz
.getOffset(GregorianCalendar::AD
, 1998, UCAL_OCTOBER
, 17,
1657 UCAL_SATURDAY
, 10 * millisPerHour
,status
);
1658 if (offset
!= -5 * U_MILLIS_PER_HOUR
)
1659 errln(UnicodeString("The offset for 10AM, 10/17/98 should have been -5 hours, but we got ")
1660 + (offset
/ U_MILLIS_PER_HOUR
) + " hours.");
1663 void TimeZoneTest::TestFractionalDST() {
1664 const char* tzName
= "Australia/Lord_Howe"; // 30 min offset
1665 TimeZone
* tz_icu
= TimeZone::createTimeZone(tzName
);
1666 int dst_icu
= tz_icu
->getDSTSavings();
1668 int32_t expected
= 1800000;
1669 if (expected
!= dst_icu
) {
1670 dataerrln(UnicodeString("java reports dst savings of ") + expected
+
1671 " but icu reports " + dst_icu
+
1672 " for tz " + tz_icu
->getID(id
));
1674 logln(UnicodeString("both java and icu report dst savings of ") + expected
+ " for tz " + tz_icu
->getID(id
));
1680 * Test country code support. Jitterbug 776.
1682 void TimeZoneTest::TestCountries() {
1683 // Make sure America/Los_Angeles is in the "US" group, and
1684 // Asia/Tokyo isn't. Vice versa for the "JP" group.
1685 UErrorCode ec
= U_ZERO_ERROR
;
1687 StringEnumeration
* s
= TimeZone::createEnumeration("US");
1689 dataerrln("Unable to create TimeZone enumeration for US");
1693 UBool la
= FALSE
, tokyo
= FALSE
;
1694 UnicodeString
laZone("America/Los_Angeles", "");
1695 UnicodeString
tokyoZone("Asia/Tokyo", "");
1698 if (s
== NULL
|| n
<= 0) {
1699 dataerrln("FAIL: TimeZone::createEnumeration() returned nothing");
1702 for (i
=0; i
<n
; ++i
) {
1703 const UnicodeString
* id
= s
->snext(ec
);
1704 if (*id
== (laZone
)) {
1707 if (*id
== (tokyoZone
)) {
1712 errln("FAIL: " + laZone
+ " in US = " + la
);
1713 errln("FAIL: " + tokyoZone
+ " in US = " + tokyo
);
1717 s
= TimeZone::createEnumeration("JP");
1719 la
= FALSE
; tokyo
= FALSE
;
1721 for (i
=0; i
<n
; ++i
) {
1722 const UnicodeString
* id
= s
->snext(ec
);
1723 if (*id
== (laZone
)) {
1726 if (*id
== (tokyoZone
)) {
1731 errln("FAIL: " + laZone
+ " in JP = " + la
);
1732 errln("FAIL: " + tokyoZone
+ " in JP = " + tokyo
);
1734 StringEnumeration
* s1
= TimeZone::createEnumeration("US");
1735 StringEnumeration
* s2
= TimeZone::createEnumeration("US");
1737 const UnicodeString
* id1
= s1
->snext(ec
);
1738 if(id1
==NULL
|| U_FAILURE(ec
)){
1739 errln("Failed to fetch next from TimeZone enumeration. Length returned : %i Current Index: %i", n
,i
);
1741 TimeZone
* tz1
= TimeZone::createTimeZone(*id1
);
1742 for(int j
=0; j
<n
;++j
){
1743 const UnicodeString
* id2
= s2
->snext(ec
);
1744 if(id2
==NULL
|| U_FAILURE(ec
)){
1745 errln("Failed to fetch next from TimeZone enumeration. Length returned : %i Current Index: %i", n
,i
);
1747 TimeZone
* tz2
= TimeZone::createTimeZone(*id2
);
1748 if(tz1
->hasSameRules(*tz2
)){
1749 logln("ID1 : " + *id1
+" == ID2 : " +*id2
);
1760 void TimeZoneTest::TestHistorical() {
1761 const int32_t H
= U_MILLIS_PER_HOUR
;
1764 int32_t time
; // epoch seconds
1765 int32_t offset
; // total offset (millis)
1767 // Add transition points (before/after) as desired to test historical
1769 {"America/Los_Angeles", 638963999, -8*H
}, // Sun Apr 01 01:59:59 GMT-08:00 1990
1770 {"America/Los_Angeles", 638964000, -7*H
}, // Sun Apr 01 03:00:00 GMT-07:00 1990
1771 {"America/Los_Angeles", 657104399, -7*H
}, // Sun Oct 28 01:59:59 GMT-07:00 1990
1772 {"America/Los_Angeles", 657104400, -8*H
}, // Sun Oct 28 01:00:00 GMT-08:00 1990
1773 {"America/Goose_Bay", -116445601, -4*H
}, // Sun Apr 24 01:59:59 GMT-04:00 1966
1774 {"America/Goose_Bay", -116445600, -3*H
}, // Sun Apr 24 03:00:00 GMT-03:00 1966
1775 {"America/Goose_Bay", -100119601, -3*H
}, // Sun Oct 30 01:59:59 GMT-03:00 1966
1776 {"America/Goose_Bay", -100119600, -4*H
}, // Sun Oct 30 01:00:00 GMT-04:00 1966
1777 {"America/Goose_Bay", -84391201, -4*H
}, // Sun Apr 30 01:59:59 GMT-04:00 1967
1778 {"America/Goose_Bay", -84391200, -3*H
}, // Sun Apr 30 03:00:00 GMT-03:00 1967
1779 {"America/Goose_Bay", -68670001, -3*H
}, // Sun Oct 29 01:59:59 GMT-03:00 1967
1780 {"America/Goose_Bay", -68670000, -4*H
}, // Sun Oct 29 01:00:00 GMT-04:00 1967
1784 for (int32_t i
=0; DATA
[i
].id
!=0; ++i
) {
1785 const char* id
= DATA
[i
].id
;
1786 TimeZone
*tz
= TimeZone::createTimeZone(id
);
1789 errln("FAIL: Cannot create %s", id
);
1790 } else if (tz
->getID(s
) != UnicodeString(id
)) {
1791 dataerrln((UnicodeString
)"FAIL: createTimeZone(" + id
+ ") => " + s
);
1793 UErrorCode ec
= U_ZERO_ERROR
;
1795 UDate when
= (double) DATA
[i
].time
* U_MILLIS_PER_SECOND
;
1796 tz
->getOffset(when
, FALSE
, raw
, dst
, ec
);
1797 if (U_FAILURE(ec
)) {
1798 errln("FAIL: getOffset");
1799 } else if ((raw
+dst
) != DATA
[i
].offset
) {
1800 errln((UnicodeString
)"FAIL: " + DATA
[i
].id
+ ".getOffset(" +
1802 dateToString(when
) + ") => " +
1805 logln((UnicodeString
)"Ok: " + DATA
[i
].id
+ ".getOffset(" +
1807 dateToString(when
) + ") => " +
1815 void TimeZoneTest::TestEquivalentIDs() {
1816 int32_t n
= TimeZone::countEquivalentIDs("PST");
1818 dataerrln((UnicodeString
)"FAIL: countEquivalentIDs(PST) = " + n
);
1820 UBool sawLA
= FALSE
;
1821 for (int32_t i
=0; i
<n
; ++i
) {
1822 UnicodeString id
= TimeZone::getEquivalentID("PST", i
);
1823 logln((UnicodeString
)"" + i
+ " : " + id
);
1824 if (id
== UnicodeString("America/Los_Angeles")) {
1829 errln("FAIL: America/Los_Angeles should be in the list");
1834 // Test that a transition at the end of February is handled correctly.
1835 void TimeZoneTest::TestFebruary() {
1836 UErrorCode status
= U_ZERO_ERROR
;
1838 // Time zone with daylight savings time from the first Sunday in November
1839 // to the last Sunday in February.
1840 // Similar to the new rule for Brazil (Sao Paulo) in tzdata2006n.
1842 // Note: In tzdata2007h, the rule had changed, so no actual zones uses
1843 // lastSun in Feb anymore.
1844 SimpleTimeZone
tz1(-3 * U_MILLIS_PER_HOUR
, // raw offset: 3h before (west of) GMT
1845 UNICODE_STRING("nov-feb", 7),
1846 UCAL_NOVEMBER
, 1, UCAL_SUNDAY
, // start: November, first, Sunday
1847 0, // midnight wall time
1848 UCAL_FEBRUARY
, -1, UCAL_SUNDAY
, // end: February, last, Sunday
1849 0, // midnight wall time
1851 if (U_FAILURE(status
)) {
1852 errln("Unable to create the SimpleTimeZone(nov-feb): %s", u_errorName(status
));
1856 // Now hardcode the same rules as for Brazil in tzdata 2006n, so that
1857 // we cover the intended code even when in the future zoneinfo hardcodes
1858 // these transition dates.
1859 SimpleTimeZone
tz2(-3 * U_MILLIS_PER_HOUR
, // raw offset: 3h before (west of) GMT
1860 UNICODE_STRING("nov-feb2", 8),
1861 UCAL_NOVEMBER
, 1, -UCAL_SUNDAY
, // start: November, 1 or after, Sunday
1862 0, // midnight wall time
1863 UCAL_FEBRUARY
, -29, -UCAL_SUNDAY
,// end: February, 29 or before, Sunday
1864 0, // midnight wall time
1866 if (U_FAILURE(status
)) {
1867 errln("Unable to create the SimpleTimeZone(nov-feb2): %s", u_errorName(status
));
1871 // Gregorian calendar with the UTC time zone for getting sample test date/times.
1872 GregorianCalendar
gc(*TimeZone::getGMT(), status
);
1873 if (U_FAILURE(status
)) {
1874 dataerrln("Unable to create the UTC calendar: %s", u_errorName(status
));
1880 int32_t year
, month
, day
, hour
, minute
, second
;
1881 // Expected time zone offset in hours after GMT (negative=before GMT).
1882 int32_t offsetHours
;
1884 { 2006, UCAL_NOVEMBER
, 5, 02, 59, 59, -3 },
1885 { 2006, UCAL_NOVEMBER
, 5, 03, 00, 00, -2 },
1886 { 2007, UCAL_FEBRUARY
, 25, 01, 59, 59, -2 },
1887 { 2007, UCAL_FEBRUARY
, 25, 02, 00, 00, -3 },
1889 { 2007, UCAL_NOVEMBER
, 4, 02, 59, 59, -3 },
1890 { 2007, UCAL_NOVEMBER
, 4, 03, 00, 00, -2 },
1891 { 2008, UCAL_FEBRUARY
, 24, 01, 59, 59, -2 },
1892 { 2008, UCAL_FEBRUARY
, 24, 02, 00, 00, -3 },
1894 { 2008, UCAL_NOVEMBER
, 2, 02, 59, 59, -3 },
1895 { 2008, UCAL_NOVEMBER
, 2, 03, 00, 00, -2 },
1896 { 2009, UCAL_FEBRUARY
, 22, 01, 59, 59, -2 },
1897 { 2009, UCAL_FEBRUARY
, 22, 02, 00, 00, -3 },
1899 { 2009, UCAL_NOVEMBER
, 1, 02, 59, 59, -3 },
1900 { 2009, UCAL_NOVEMBER
, 1, 03, 00, 00, -2 },
1901 { 2010, UCAL_FEBRUARY
, 28, 01, 59, 59, -2 },
1902 { 2010, UCAL_FEBRUARY
, 28, 02, 00, 00, -3 }
1905 TimeZone
*timezones
[] = { &tz1
, &tz2
};
1909 int32_t t
, i
, raw
, dst
;
1910 for (t
= 0; t
< LENGTHOF(timezones
); ++t
) {
1912 for (i
= 0; i
< LENGTHOF(data
); ++i
) {
1913 gc
.set(data
[i
].year
, data
[i
].month
, data
[i
].day
,
1914 data
[i
].hour
, data
[i
].minute
, data
[i
].second
);
1915 dt
= gc
.getTime(status
);
1916 if (U_FAILURE(status
)) {
1917 errln("test case %d.%d: bad date/time %04d-%02d-%02d %02d:%02d:%02d",
1919 data
[i
].year
, data
[i
].month
+ 1, data
[i
].day
,
1920 data
[i
].hour
, data
[i
].minute
, data
[i
].second
);
1921 status
= U_ZERO_ERROR
;
1924 tz
->getOffset(dt
, FALSE
, raw
, dst
, status
);
1925 if (U_FAILURE(status
)) {
1926 errln("test case %d.%d: tz.getOffset(%04d-%02d-%02d %02d:%02d:%02d) fails: %s",
1928 data
[i
].year
, data
[i
].month
+ 1, data
[i
].day
,
1929 data
[i
].hour
, data
[i
].minute
, data
[i
].second
,
1930 u_errorName(status
));
1931 status
= U_ZERO_ERROR
;
1932 } else if ((raw
+ dst
) != data
[i
].offsetHours
* U_MILLIS_PER_HOUR
) {
1933 errln("test case %d.%d: tz.getOffset(%04d-%02d-%02d %02d:%02d:%02d) returns %d+%d != %d",
1935 data
[i
].year
, data
[i
].month
+ 1, data
[i
].day
,
1936 data
[i
].hour
, data
[i
].minute
, data
[i
].second
,
1937 raw
, dst
, data
[i
].offsetHours
* U_MILLIS_PER_HOUR
);
1943 void TimeZoneTest::TestCanonicalIDAPI() {
1944 // Bogus input string.
1945 UnicodeString bogus
;
1947 UnicodeString canonicalID
;
1948 UErrorCode ec
= U_ZERO_ERROR
;
1949 UnicodeString
*pResult
= &TimeZone::getCanonicalID(bogus
, canonicalID
, ec
);
1950 assertEquals("TimeZone::getCanonicalID(bogus) should fail", U_ILLEGAL_ARGUMENT_ERROR
, ec
);
1951 assertTrue("TimeZone::getCanonicalID(bogus) should return the dest string", pResult
== &canonicalID
);
1953 // U_FAILURE on input.
1954 UnicodeString
berlin("Europe/Berlin");
1955 ec
= U_MEMORY_ALLOCATION_ERROR
;
1956 pResult
= &TimeZone::getCanonicalID(berlin
, canonicalID
, ec
);
1957 assertEquals("TimeZone::getCanonicalID(failure) should fail", U_MEMORY_ALLOCATION_ERROR
, ec
);
1958 assertTrue("TimeZone::getCanonicalID(failure) should return the dest string", pResult
== &canonicalID
);
1960 // Valid input should un-bogus the dest string.
1961 canonicalID
.setToBogus();
1963 pResult
= &TimeZone::getCanonicalID(berlin
, canonicalID
, ec
);
1964 assertSuccess("TimeZone::getCanonicalID(bogus dest) should succeed", ec
, TRUE
);
1965 assertTrue("TimeZone::getCanonicalID(bogus dest) should return the dest string", pResult
== &canonicalID
);
1966 assertFalse("TimeZone::getCanonicalID(bogus dest) should un-bogus the dest string", canonicalID
.isBogus());
1967 assertEquals("TimeZone::getCanonicalID(bogus dest) unexpected result", canonicalID
, berlin
, TRUE
);
1970 void TimeZoneTest::TestCanonicalID() {
1972 // Some canonical IDs in CLDR are defined as "Link"
1974 static const struct {
1978 {"Africa/Addis_Ababa", "Africa/Nairobi"},
1979 {"Africa/Asmera", "Africa/Nairobi"},
1980 {"Africa/Bamako", "Africa/Abidjan"},
1981 {"Africa/Bangui", "Africa/Lagos"},
1982 {"Africa/Banjul", "Africa/Abidjan"},
1983 {"Africa/Blantyre", "Africa/Maputo"},
1984 {"Africa/Brazzaville", "Africa/Lagos"},
1985 {"Africa/Bujumbura", "Africa/Maputo"},
1986 {"Africa/Conakry", "Africa/Abidjan"},
1987 {"Africa/Dakar", "Africa/Abidjan"},
1988 {"Africa/Dar_es_Salaam", "Africa/Nairobi"},
1989 {"Africa/Djibouti", "Africa/Nairobi"},
1990 {"Africa/Douala", "Africa/Lagos"},
1991 {"Africa/Freetown", "Africa/Abidjan"},
1992 {"Africa/Gaborone", "Africa/Maputo"},
1993 {"Africa/Harare", "Africa/Maputo"},
1994 {"Africa/Kampala", "Africa/Nairobi"},
1995 {"Africa/Khartoum", "Africa/Juba"},
1996 {"Africa/Kigali", "Africa/Maputo"},
1997 {"Africa/Kinshasa", "Africa/Lagos"},
1998 {"Africa/Libreville", "Africa/Lagos"},
1999 {"Africa/Lome", "Africa/Abidjan"},
2000 {"Africa/Luanda", "Africa/Lagos"},
2001 {"Africa/Lubumbashi", "Africa/Maputo"},
2002 {"Africa/Lusaka", "Africa/Maputo"},
2003 {"Africa/Maseru", "Africa/Johannesburg"},
2004 {"Africa/Malabo", "Africa/Lagos"},
2005 {"Africa/Mbabane", "Africa/Johannesburg"},
2006 {"Africa/Mogadishu", "Africa/Nairobi"},
2007 {"Africa/Niamey", "Africa/Lagos"},
2008 {"Africa/Nouakchott", "Africa/Abidjan"},
2009 {"Africa/Ouagadougou", "Africa/Abidjan"},
2010 {"Africa/Porto-Novo", "Africa/Lagos"},
2011 {"Africa/Sao_Tome", "Africa/Abidjan"},
2012 {"America/Curacao", "America/Aruba"},
2013 {"America/Dominica", "America/Anguilla"},
2014 {"America/Grenada", "America/Anguilla"},
2015 {"America/Guadeloupe", "America/Anguilla"},
2016 {"America/Kralendijk", "America/Aruba"},
2017 {"America/Lower_Princes", "America/Aruba"},
2018 {"America/Marigot", "America/Anguilla"},
2019 {"America/Montserrat", "America/Anguilla"},
2020 {"America/Port_of_Spain", "America/Anguilla"},
2021 {"America/Shiprock", "America/Denver"}, // America/Shiprock is defined as a Link to America/Denver in tzdata
2022 {"America/St_Barthelemy", "America/Anguilla"},
2023 {"America/St_Kitts", "America/Anguilla"},
2024 {"America/St_Lucia", "America/Anguilla"},
2025 {"America/St_Thomas", "America/Anguilla"},
2026 {"America/St_Vincent", "America/Anguilla"},
2027 {"America/Tortola", "America/Anguilla"},
2028 {"America/Virgin", "America/Anguilla"},
2029 {"Antarctica/South_Pole", "Antarctica/McMurdo"},
2030 {"Arctic/Longyearbyen", "Europe/Oslo"},
2031 {"Asia/Phnom_Penh", "Asia/Bangkok"},
2032 {"Asia/Vientiane", "Asia/Bangkok"},
2033 {"Atlantic/Jan_Mayen", "Europe/Oslo"},
2034 {"Atlantic/St_Helena", "Africa/Abidjan"},
2035 {"Europe/Bratislava", "Europe/Prague"},
2036 {"Europe/Busingen", "Europe/Zurich"},
2037 {"Europe/Guernsey", "Europe/London"},
2038 {"Europe/Isle_of_Man", "Europe/London"},
2039 {"Europe/Jersey", "Europe/London"},
2040 {"Europe/Ljubljana", "Europe/Belgrade"},
2041 {"Europe/Mariehamn", "Europe/Helsinki"},
2042 {"Europe/Podgorica", "Europe/Belgrade"},
2043 {"Europe/San_Marino", "Europe/Rome"},
2044 {"Europe/Sarajevo", "Europe/Belgrade"},
2045 {"Europe/Skopje", "Europe/Belgrade"},
2046 {"Europe/Vaduz", "Europe/Zurich"},
2047 {"Europe/Vatican", "Europe/Rome"},
2048 {"Europe/Zagreb", "Europe/Belgrade"},
2049 {"Indian/Antananarivo", "Africa/Nairobi"},
2050 {"Indian/Comoro", "Africa/Nairobi"},
2051 {"Indian/Mayotte", "Africa/Nairobi"},
2052 {"Pacific/Auckland", "Antarctica/McMurdo"},
2053 {"Pacific/Johnston", "Pacific/Honolulu"},
2057 // Following IDs are aliases of Etc/GMT in CLDR,
2058 // but Olson tzdata has 3 independent definitions
2059 // for Etc/GMT, Etc/UTC, Etc/UCT.
2060 // Until we merge them into one equivalent group
2061 // in zoneinfo.res, we exclude them in the test
2063 static const char* excluded2
[] = {
2066 "Etc/Universal", "Universal",
2067 "Etc/Zulu", "Zulu", 0
2070 // Walk through equivalency groups
2071 UErrorCode ec
= U_ZERO_ERROR
;
2072 int32_t s_length
, i
, j
, k
;
2073 StringEnumeration
* s
= TimeZone::createEnumeration();
2075 dataerrln("Unable to create TimeZone enumeration");
2078 UnicodeString canonicalID
, tmpCanonical
;
2079 s_length
= s
->count(ec
);
2080 for (i
= 0; i
< s_length
;++i
) {
2081 const UnicodeString
*tzid
= s
->snext(ec
);
2082 int32_t nEquiv
= TimeZone::countEquivalentIDs(*tzid
);
2086 UBool bFoundCanonical
= FALSE
;
2087 // Make sure getCanonicalID returns the exact same result
2088 // for all entries within a same equivalency group with some
2089 // exceptions listed in exluded1.
2090 // Also, one of them must be canonical id.
2091 for (j
= 0; j
< nEquiv
; j
++) {
2092 UnicodeString tmp
= TimeZone::getEquivalentID(*tzid
, j
);
2093 TimeZone::getCanonicalID(tmp
, tmpCanonical
, ec
);
2094 if (U_FAILURE(ec
)) {
2095 errln((UnicodeString
)"FAIL: getCanonicalID(" + tmp
+ ") failed.");
2099 // Some exceptional cases
2100 for (k
= 0; excluded1
[k
].alias
!= 0; k
++) {
2101 if (tmpCanonical
== excluded1
[k
].alias
) {
2102 tmpCanonical
= excluded1
[k
].zone
;
2107 canonicalID
= tmpCanonical
;
2108 } else if (canonicalID
!= tmpCanonical
) {
2109 errln("FAIL: getCanonicalID(" + tmp
+ ") returned " + tmpCanonical
+ " expected:" + canonicalID
);
2112 if (canonicalID
== tmp
) {
2113 bFoundCanonical
= TRUE
;
2116 // At least one ID in an equvalency group must match the
2118 if (bFoundCanonical
== FALSE
) {
2119 // test exclusion because of differences between Olson tzdata and CLDR
2120 UBool isExcluded
= FALSE
;
2121 for (k
= 0; excluded2
[k
] != 0; k
++) {
2122 if (*tzid
== UnicodeString(excluded2
[k
])) {
2130 errln((UnicodeString
)"FAIL: No timezone ids match the canonical ID " + canonicalID
);
2135 // Testing some special cases
2136 static const struct {
2138 const char *expected
;
2141 {"GMT-03", "GMT-03:00", FALSE
},
2142 {"GMT+4", "GMT+04:00", FALSE
},
2143 {"GMT-055", "GMT-00:55", FALSE
},
2144 {"GMT+430", "GMT+04:30", FALSE
},
2145 {"GMT-12:15", "GMT-12:15", FALSE
},
2146 {"GMT-091015", "GMT-09:10:15", FALSE
},
2147 {"GMT+1:90", 0, FALSE
},
2148 {"America/Argentina/Buenos_Aires", "America/Buenos_Aires", TRUE
},
2149 {"Etc/Unknown", "Etc/Unknown", FALSE
},
2150 {"bogus", 0, FALSE
},
2152 {"America/Marigot", "America/Marigot", TRUE
}, // Olson link, but CLDR canonical (#8953)
2153 {"Europe/Bratislava", "Europe/Bratislava", TRUE
}, // Same as above
2158 for (i
= 0; data
[i
].id
!= 0; i
++) {
2159 TimeZone::getCanonicalID(UnicodeString(data
[i
].id
), canonicalID
, isSystemID
, ec
);
2160 if (U_FAILURE(ec
)) {
2161 if (ec
!= U_ILLEGAL_ARGUMENT_ERROR
|| data
[i
].expected
!= 0) {
2162 errln((UnicodeString
)"FAIL: getCanonicalID(\"" + data
[i
].id
2163 + "\") returned status U_ILLEGAL_ARGUMENT_ERROR");
2168 if (canonicalID
!= data
[i
].expected
) {
2169 dataerrln((UnicodeString
)"FAIL: getCanonicalID(\"" + data
[i
].id
2170 + "\") returned " + canonicalID
+ " - expected: " + data
[i
].expected
);
2172 if (isSystemID
!= data
[i
].isSystem
) {
2173 dataerrln((UnicodeString
)"FAIL: getCanonicalID(\"" + data
[i
].id
2174 + "\") set " + isSystemID
+ " to isSystemID");
2180 // Test Display Names, choosing zones and lcoales where there are multiple
2181 // meta-zones defined.
2184 const char *zoneName
;
2185 const char *localeName
;
2187 TimeZone::EDisplayType style
;
2188 const char *expectedDisplayName
; }
2189 zoneDisplayTestData
[] = {
2190 // zone id locale summer format expected display name
2191 {"Europe/London", "en", FALSE
, TimeZone::SHORT
, "GMT"},
2192 {"Europe/London", "en", FALSE
, TimeZone::LONG
, "Greenwich Mean Time"},
2193 {"Europe/London", "en", TRUE
, TimeZone::SHORT
, "GMT+1" /*"BST"*/},
2194 {"Europe/London", "en", TRUE
, TimeZone::LONG
, "British Summer Time"},
2196 {"America/Anchorage", "en", FALSE
, TimeZone::SHORT
, "AKST"},
2197 {"America/Anchorage", "en", FALSE
, TimeZone::LONG
, "Alaska Standard Time"},
2198 {"America/Anchorage", "en", TRUE
, TimeZone::SHORT
, "AKDT"},
2199 {"America/Anchorage", "en", TRUE
, TimeZone::LONG
, "Alaska Daylight Time"},
2201 // Southern Hemisphere, all data from meta:Australia_Western
2202 {"Australia/Perth", "en", FALSE
, TimeZone::SHORT
, "GMT+8"/*"AWST"*/},
2203 {"Australia/Perth", "en", FALSE
, TimeZone::LONG
, "Australian Western Standard Time"},
2204 // Note: Perth does not observe DST currently. When display name is missing,
2205 // the localized GMT format with the current offset is used even daylight name was
2206 // requested. See #9350.
2207 {"Australia/Perth", "en", TRUE
, TimeZone::SHORT
, "GMT+8"/*"AWDT"*/},
2208 {"Australia/Perth", "en", TRUE
, TimeZone::LONG
, "Australian Western Daylight Time"},
2210 {"America/Sao_Paulo", "en", FALSE
, TimeZone::SHORT
, "GMT-3"/*"BRT"*/},
2211 {"America/Sao_Paulo", "en", FALSE
, TimeZone::LONG
, "Brasilia Standard Time"},
2212 {"America/Sao_Paulo", "en", TRUE
, TimeZone::SHORT
, "GMT-2"/*"BRST"*/},
2213 {"America/Sao_Paulo", "en", TRUE
, TimeZone::LONG
, "Brasilia Summer Time"},
2215 // No Summer Time, but had it before 1983.
2216 {"Pacific/Honolulu", "en", FALSE
, TimeZone::SHORT
, "HST"},
2217 {"Pacific/Honolulu", "en", FALSE
, TimeZone::LONG
, "Hawaii-Aleutian Standard Time"},
2218 {"Pacific/Honolulu", "en", TRUE
, TimeZone::SHORT
, "HDT"},
2219 {"Pacific/Honolulu", "en", TRUE
, TimeZone::LONG
, "Hawaii-Aleutian Daylight Time"},
2221 // Northern, has Summer, not commonly used.
2222 {"Europe/Helsinki", "en", FALSE
, TimeZone::SHORT
, "GMT+2"/*"EET"*/},
2223 {"Europe/Helsinki", "en", FALSE
, TimeZone::LONG
, "Eastern European Standard Time"},
2224 {"Europe/Helsinki", "en", TRUE
, TimeZone::SHORT
, "GMT+3"/*"EEST"*/},
2225 {"Europe/Helsinki", "en", TRUE
, TimeZone::LONG
, "Eastern European Summer Time"},
2227 // Repeating the test data for DST. The test data below trigger the problem reported
2229 {"Europe/London", "en", TRUE
, TimeZone::SHORT
, "GMT+1" /*"BST"*/},
2230 {"Europe/London", "en", TRUE
, TimeZone::LONG
, "British Summer Time"},
2232 {NULL
, NULL
, FALSE
, TimeZone::SHORT
, NULL
} // NULL values terminate list
2235 void TimeZoneTest::TestDisplayNamesMeta() {
2236 UErrorCode status
= U_ZERO_ERROR
;
2237 GregorianCalendar
cal(*TimeZone::getGMT(), status
);
2238 if (failure(status
, "GregorianCalendar", TRUE
)) return;
2240 UBool sawAnError
= FALSE
;
2241 for (int testNum
= 0; zoneDisplayTestData
[testNum
].zoneName
!= NULL
; testNum
++) {
2242 Locale locale
= Locale::createFromName(zoneDisplayTestData
[testNum
].localeName
);
2243 TimeZone
*zone
= TimeZone::createTimeZone(zoneDisplayTestData
[testNum
].zoneName
);
2244 UnicodeString displayName
;
2245 zone
->getDisplayName(zoneDisplayTestData
[testNum
].summerTime
,
2246 zoneDisplayTestData
[testNum
].style
,
2249 if (displayName
!= zoneDisplayTestData
[testNum
].expectedDisplayName
) {
2251 UErrorCode status
= U_ZERO_ERROR
;
2252 displayName
.extract(name
, 100, NULL
, status
);
2253 if (isDevelopmentBuild
) {
2255 dataerrln("Incorrect time zone display name. zone = \"%s\",\n"
2256 " locale = \"%s\", style = %s, Summertime = %d\n"
2257 " Expected \"%s\", "
2258 " Got \"%s\"\n Error: %s", zoneDisplayTestData
[testNum
].zoneName
,
2259 zoneDisplayTestData
[testNum
].localeName
,
2260 zoneDisplayTestData
[testNum
].style
==TimeZone::SHORT
?
2262 zoneDisplayTestData
[testNum
].summerTime
,
2263 zoneDisplayTestData
[testNum
].expectedDisplayName
,
2265 u_errorName(status
));
2267 logln("Incorrect time zone display name. zone = \"%s\",\n"
2268 " locale = \"%s\", style = %s, Summertime = %d\n"
2269 " Expected \"%s\", "
2270 " Got \"%s\"\n", zoneDisplayTestData
[testNum
].zoneName
,
2271 zoneDisplayTestData
[testNum
].localeName
,
2272 zoneDisplayTestData
[testNum
].style
==TimeZone::SHORT
?
2274 zoneDisplayTestData
[testNum
].summerTime
,
2275 zoneDisplayTestData
[testNum
].expectedDisplayName
,
2282 dataerrln("***Note: Errors could be the result of changes to zoneStrings locale data");
2286 void TimeZoneTest::TestGetRegion()
2288 static const struct {
2292 {"America/Los_Angeles", "US"},
2293 {"America/Indianapolis", "US"}, // CLDR canonical, Olson backward
2294 {"America/Indiana/Indianapolis", "US"}, // CLDR alias
2295 {"Mexico/General", "MX"}, // Link America/Mexico_City, Olson backward
2298 {"PST", "US"}, // Link America/Los_Angeles
2299 {"Europe/Helsinki", "FI"},
2300 {"Europe/Mariehamn", "AX"}, // Link Europe/Helsinki, but in zone.tab
2301 {"Asia/Riyadh", "SA"},
2302 // tz file solar87 was removed from tzdata2013i
2303 // {"Asia/Riyadh87", "001"}, // this should be "SA" actually, but not in zone.tab
2304 {"Etc/Unknown", 0}, // CLDR canonical, but not a sysmte zone ID
2305 {"bogus", 0}, // bogus
2306 {"GMT+08:00", 0}, // a custom ID, not a system zone ID
2313 for (i
= 0; data
[i
].id
; i
++) {
2315 TimeZone::getRegion(data
[i
].id
, region
, sizeof(region
), sts
);
2316 if (U_SUCCESS(sts
)) {
2317 if (data
[i
].region
== 0) {
2318 errln((UnicodeString
)"Fail: getRegion(\"" + data
[i
].id
+ "\") returns "
2319 + region
+ " [expected: U_ILLEGAL_ARGUMENT_ERROR]");
2320 } else if (uprv_strcmp(region
, data
[i
].region
) != 0) {
2321 errln((UnicodeString
)"Fail: getRegion(\"" + data
[i
].id
+ "\") returns "
2322 + region
+ " [expected: " + data
[i
].region
+ "]");
2324 } else if (sts
== U_ILLEGAL_ARGUMENT_ERROR
) {
2325 if (data
[i
].region
!= 0) {
2326 dataerrln((UnicodeString
)"Fail: getRegion(\"" + data
[i
].id
2327 + "\") returns error status U_ILLEGAL_ARGUMENT_ERROR [expected: "
2328 + data
[i
].region
+ "]");
2331 errln((UnicodeString
)"Fail: getRegion(\"" + data
[i
].id
2332 + "\") returns an unexpected error status");
2336 // Extra test cases for short buffer
2341 len
= TimeZone::getRegion("America/New_York", region2
, sizeof(region2
), sts
);
2342 if (sts
== U_ILLEGAL_ARGUMENT_ERROR
) {
2343 dataerrln("Error calling TimeZone::getRegion");
2345 if (sts
!= U_STRING_NOT_TERMINATED_WARNING
) {
2346 errln("Expected U_STRING_NOT_TERMINATED_WARNING");
2348 if (len
!= 2) { // length of "US"
2349 errln("Incorrect result length");
2351 if (uprv_strncmp(region2
, "US", 2) != 0) {
2352 errln("Incorrect result");
2359 len
= TimeZone::getRegion("America/Chicago", region1
, sizeof(region1
), sts
);
2360 if (sts
== U_ILLEGAL_ARGUMENT_ERROR
) {
2361 dataerrln("Error calling TimeZone::getRegion");
2363 if (sts
!= U_BUFFER_OVERFLOW_ERROR
) {
2364 errln("Expected U_BUFFER_OVERFLOW_ERROR");
2366 if (len
!= 2) { // length of "US"
2367 errln("Incorrect result length");
2372 void TimeZoneTest::TestGetUnknown() {
2373 const TimeZone
&unknown
= TimeZone::getUnknown();
2374 UnicodeString expectedID
= UNICODE_STRING_SIMPLE("Etc/Unknown");
2376 assertEquals("getUnknown() wrong ID", expectedID
, unknown
.getID(id
));
2377 assertTrue("getUnknown() wrong offset", 0 == unknown
.getRawOffset());
2378 assertFalse("getUnknown() uses DST", unknown
.useDaylightTime());
2381 void TimeZoneTest::TestGetWindowsID(void) {
2382 static const struct {
2386 {"America/New_York", "Eastern Standard Time"},
2387 {"America/Montreal", "Eastern Standard Time"},
2388 {"America/Los_Angeles", "Pacific Standard Time"},
2389 {"America/Vancouver", "Pacific Standard Time"},
2390 {"Asia/Shanghai", "China Standard Time"},
2391 {"Asia/Chongqing", "China Standard Time"},
2392 {"America/Indianapolis", "US Eastern Standard Time"}, // CLDR canonical name
2393 {"America/Indiana/Indianapolis", "US Eastern Standard Time"}, // tzdb canonical name
2394 {"Asia/Khandyga", "Yakutsk Standard Time"},
2395 {"Australia/Eucla", ""}, // No Windows ID mapping
2400 for (int32_t i
= 0; TESTDATA
[i
].id
!= 0; i
++) {
2401 UErrorCode sts
= U_ZERO_ERROR
;
2402 UnicodeString windowsID
;
2404 TimeZone::getWindowsID(UnicodeString(TESTDATA
[i
].id
), windowsID
, sts
);
2405 assertSuccess(TESTDATA
[i
].id
, sts
);
2406 assertEquals(TESTDATA
[i
].id
, UnicodeString(TESTDATA
[i
].winid
), windowsID
, TRUE
);
2410 void TimeZoneTest::TestGetIDForWindowsID(void) {
2411 static const struct {
2416 {"Eastern Standard Time", 0, "America/New_York"},
2417 {"Eastern Standard Time", "US", "America/New_York"},
2418 {"Eastern Standard Time", "CA", "America/Toronto"},
2419 {"Eastern Standard Time", "CN", "America/New_York"},
2420 {"China Standard Time", 0, "Asia/Shanghai"},
2421 {"China Standard Time", "CN", "Asia/Shanghai"},
2422 {"China Standard Time", "HK", "Asia/Hong_Kong"},
2423 {"Mid-Atlantic Standard Time", 0, ""}, // No tz database mapping
2428 for (int32_t i
= 0; TESTDATA
[i
].winid
!= 0; i
++) {
2429 UErrorCode sts
= U_ZERO_ERROR
;
2432 TimeZone::getIDForWindowsID(UnicodeString(TESTDATA
[i
].winid
), TESTDATA
[i
].region
,
2434 assertSuccess(UnicodeString(TESTDATA
[i
].winid
) + "/" + TESTDATA
[i
].region
, sts
);
2435 assertEquals(UnicodeString(TESTDATA
[i
].winid
) + "/" + TESTDATA
[i
].region
, TESTDATA
[i
].id
, id
, TRUE
);
2439 #endif /* #if !UCONFIG_NO_FORMATTING */