• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***********************************************************************
2  * COPYRIGHT:
3  * Copyright (c) 1997-2007, International Business Machines Corporation
4  * and others. All Rights Reserved.
5  ***********************************************************************/
6 
7 #include "unicode/utypes.h"
8 
9 #if !UCONFIG_NO_FORMATTING
10 
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 "tztest.h"
18 #include "cmemory.h"
19 #include "putilimp.h"
20 #include "cstring.h"
21 #include "olsontz.h"
22 
23 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
24 
25 #define CASE(id,test) case id:                               \
26                           name = #test;                      \
27                           if (exec) {                        \
28                               logln(#test "---"); logln(""); \
29                               test();                        \
30                           }                                  \
31                           break
32 
33 // *****************************************************************************
34 // class TimeZoneTest
35 // *****************************************************************************
36 
runIndexedTest(int32_t index,UBool exec,const char * & name,char *)37 void TimeZoneTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
38 {
39     if (exec) logln("TestSuite TestTimeZone");
40     switch (index) {
41         CASE(0, TestPRTOffset);
42         CASE(1, TestVariousAPI518);
43         CASE(2, TestGetAvailableIDs913);
44         CASE(3, TestGenericAPI);
45         CASE(4, TestRuleAPI);
46         CASE(5, TestShortZoneIDs);
47         CASE(6, TestCustomParse);
48         CASE(7, TestDisplayName);
49         CASE(8, TestDSTSavings);
50         CASE(9, TestAlternateRules);
51         CASE(10,TestCountries);
52         CASE(11,TestHistorical);
53         CASE(12,TestEquivalentIDs);
54         CASE(13, TestAliasedNames);
55         CASE(14, TestFractionalDST);
56         CASE(15, TestFebruary);
57        default: name = ""; break;
58     }
59 }
60 
61 const int32_t TimeZoneTest::millisPerHour = 3600000;
62 
63 // ---------------------------------------------------------------------------------
64 
65 /**
66  * Generic API testing for API coverage.
67  */
68 void
TestGenericAPI()69 TimeZoneTest::TestGenericAPI()
70 {
71     UnicodeString id("NewGMT");
72     int32_t offset = 12345;
73 
74     SimpleTimeZone *zone = new SimpleTimeZone(offset, id);
75     if (zone->useDaylightTime()) errln("FAIL: useDaylightTime should return FALSE");
76 
77     TimeZone* zoneclone = zone->clone();
78     if (!(*zoneclone == *zone)) errln("FAIL: clone or operator== failed");
79     zoneclone->setID("abc");
80     if (!(*zoneclone != *zone)) errln("FAIL: clone or operator!= failed");
81     delete zoneclone;
82 
83     zoneclone = zone->clone();
84     if (!(*zoneclone == *zone)) errln("FAIL: clone or operator== failed");
85     zoneclone->setRawOffset(45678);
86     if (!(*zoneclone != *zone)) errln("FAIL: clone or operator!= failed");
87 
88     SimpleTimeZone copy(*zone);
89     if (!(copy == *zone)) errln("FAIL: copy constructor or operator== failed");
90     copy = *(SimpleTimeZone*)zoneclone;
91     if (!(copy == *zoneclone)) errln("FAIL: assignment operator or operator== failed");
92 
93     TimeZone* saveDefault = TimeZone::createDefault();
94     logln((UnicodeString)"TimeZone::createDefault() => " + saveDefault->getID(id));
95     TimeZone* pstZone = TimeZone::createTimeZone("America/Los_Angeles");
96 
97     logln("call uprv_timezone() which uses the host");
98     logln("to get the difference in seconds between coordinated universal");
99     logln("time and local time. E.g., -28,800 for PST (GMT-8hrs)");
100 
101     int32_t tzoffset = uprv_timezone();
102     logln(UnicodeString("Value returned from uprv_timezone = ") + tzoffset);
103     // Invert sign because UNIX semantics are backwards
104     if (tzoffset < 0)
105         tzoffset = -tzoffset;
106     if ((*saveDefault == *pstZone) && (tzoffset != 28800)) {
107         errln("FAIL: t_timezone may be incorrect.  It is not 28800");
108     }
109 
110     if ((tzoffset % 900) != 0) {
111         errln("FAIL: t_timezone may be incorrect. It is not a multiple of 15min. It is %d", tzoffset);
112     }
113 
114     TimeZone::adoptDefault(zone);
115     TimeZone* defaultzone = TimeZone::createDefault();
116     if (defaultzone == zone ||
117         !(*defaultzone == *zone))
118         errln("FAIL: createDefault failed");
119     TimeZone::adoptDefault(saveDefault);
120     delete defaultzone;
121     delete zoneclone;
122     delete pstZone;
123 
124     UErrorCode status = U_ZERO_ERROR;
125     const char* tzver = TimeZone::getTZDataVersion(status);
126     if (U_FAILURE(status)) {
127         errln("FAIL: getTZDataVersion failed");
128     } else if (uprv_strlen(tzver) != 5 /* 4 digits + 1 letter */) {
129         errln((UnicodeString)"FAIL: getTZDataVersion returned " + tzver);
130     } else {
131         logln((UnicodeString)"tzdata version: " + tzver);
132     }
133 }
134 
135 // ---------------------------------------------------------------------------------
136 
137 /**
138  * Test the setStartRule/setEndRule API calls.
139  */
140 void
TestRuleAPI()141 TimeZoneTest::TestRuleAPI()
142 {
143     UErrorCode status = U_ZERO_ERROR;
144 
145     UDate offset = 60*60*1000*1.75; // Pick a weird offset
146     SimpleTimeZone *zone = new SimpleTimeZone((int32_t)offset, "TestZone");
147     if (zone->useDaylightTime()) errln("FAIL: useDaylightTime should return FALSE");
148 
149     // Establish our expected transition times.  Do this with a non-DST
150     // calendar with the (above) declared local offset.
151     GregorianCalendar *gc = new GregorianCalendar(*zone, status);
152     if (failure(status, "new GregorianCalendar")) return;
153     gc->clear();
154     gc->set(1990, UCAL_MARCH, 1);
155     UDate marchOneStd = gc->getTime(status); // Local Std time midnight
156     gc->clear();
157     gc->set(1990, UCAL_JULY, 1);
158     UDate julyOneStd = gc->getTime(status); // Local Std time midnight
159     if (failure(status, "GregorianCalendar::getTime")) return;
160 
161     // Starting and ending hours, WALL TIME
162     int32_t startHour = (int32_t)(2.25 * 3600000);
163     int32_t endHour   = (int32_t)(3.5  * 3600000);
164 
165     zone->setStartRule(UCAL_MARCH, 1, 0, startHour, status);
166     zone->setEndRule  (UCAL_JULY,  1, 0, endHour, status);
167 
168     delete gc;
169     gc = new GregorianCalendar(*zone, status);
170     if (failure(status, "new GregorianCalendar")) return;
171 
172     UDate marchOne = marchOneStd + startHour;
173     UDate julyOne = julyOneStd + endHour - 3600000; // Adjust from wall to Std time
174 
175     UDate expMarchOne = 636251400000.0;
176     if (marchOne != expMarchOne)
177     {
178         errln((UnicodeString)"FAIL: Expected start computed as " + marchOne +
179           " = " + dateToString(marchOne));
180         logln((UnicodeString)"      Should be                  " + expMarchOne +
181           " = " + dateToString(expMarchOne));
182     }
183 
184     UDate expJulyOne = 646793100000.0;
185     if (julyOne != expJulyOne)
186     {
187         errln((UnicodeString)"FAIL: Expected start computed as " + julyOne +
188           " = " + dateToString(julyOne));
189         logln((UnicodeString)"      Should be                  " + expJulyOne +
190           " = " + dateToString(expJulyOne));
191     }
192 
193     testUsingBinarySearch(*zone, date(90, UCAL_JANUARY, 1), date(90, UCAL_JUNE, 15), marchOne);
194     testUsingBinarySearch(*zone, date(90, UCAL_JUNE, 1), date(90, UCAL_DECEMBER, 31), julyOne);
195 
196     if (zone->inDaylightTime(marchOne - 1000, status) ||
197         !zone->inDaylightTime(marchOne, status))
198         errln("FAIL: Start rule broken");
199     if (!zone->inDaylightTime(julyOne - 1000, status) ||
200         zone->inDaylightTime(julyOne, status))
201         errln("FAIL: End rule broken");
202 
203     zone->setStartYear(1991);
204     if (zone->inDaylightTime(marchOne, status) ||
205         zone->inDaylightTime(julyOne - 1000, status))
206         errln("FAIL: Start year broken");
207 
208     failure(status, "TestRuleAPI");
209     delete gc;
210     delete zone;
211 }
212 
213 void
findTransition(const TimeZone & tz,UDate min,UDate max)214 TimeZoneTest::findTransition(const TimeZone& tz,
215                              UDate min, UDate max) {
216     UErrorCode ec = U_ZERO_ERROR;
217     UnicodeString id,s;
218     UBool startsInDST = tz.inDaylightTime(min, ec);
219     if (failure(ec, "TimeZone::inDaylightTime")) return;
220     if (tz.inDaylightTime(max, ec) == startsInDST) {
221         logln("Error: " + tz.getID(id) + ".inDaylightTime(" + dateToString(min) + ") = " + (startsInDST?"TRUE":"FALSE") +
222               ", inDaylightTime(" + dateToString(max) + ") = " + (startsInDST?"TRUE":"FALSE"));
223         return;
224     }
225     if (failure(ec, "TimeZone::inDaylightTime")) return;
226     while ((max - min) > INTERVAL) {
227         UDate mid = (min + max) / 2;
228         if (tz.inDaylightTime(mid, ec) == startsInDST) {
229             min = mid;
230         } else {
231             max = mid;
232         }
233         if (failure(ec, "TimeZone::inDaylightTime")) return;
234     }
235     min = 1000.0 * uprv_floor(min/1000.0);
236     max = 1000.0 * uprv_floor(max/1000.0);
237     logln(tz.getID(id) + " Before: " + min/1000 + " = " +
238           dateToString(min,s,tz));
239     logln(tz.getID(id) + " After:  " + max/1000 + " = " +
240           dateToString(max,s,tz));
241 }
242 
243 void
testUsingBinarySearch(const TimeZone & tz,UDate min,UDate max,UDate expectedBoundary)244 TimeZoneTest::testUsingBinarySearch(const TimeZone& tz,
245                                     UDate min, UDate max,
246                                     UDate expectedBoundary)
247 {
248     UErrorCode status = U_ZERO_ERROR;
249     UBool startsInDST = tz.inDaylightTime(min, status);
250     if (failure(status, "TimeZone::inDaylightTime")) return;
251     if (tz.inDaylightTime(max, status) == startsInDST) {
252         logln("Error: inDaylightTime(" + dateToString(max) + ") != " + ((!startsInDST)?"TRUE":"FALSE"));
253         return;
254     }
255     if (failure(status, "TimeZone::inDaylightTime")) return;
256     while ((max - min) > INTERVAL) {
257         UDate mid = (min + max) / 2;
258         if (tz.inDaylightTime(mid, status) == startsInDST) {
259             min = mid;
260         } else {
261             max = mid;
262         }
263         if (failure(status, "TimeZone::inDaylightTime")) return;
264     }
265     logln(UnicodeString("Binary Search Before: ") + uprv_floor(0.5 + min) + " = " + dateToString(min));
266     logln(UnicodeString("Binary Search After:  ") + uprv_floor(0.5 + max) + " = " + dateToString(max));
267     UDate mindelta = expectedBoundary - min;
268     UDate maxdelta = max - expectedBoundary;
269     if (mindelta >= 0 &&
270         mindelta <= INTERVAL &&
271         maxdelta >= 0 &&
272         maxdelta <= INTERVAL)
273         logln(UnicodeString("PASS: Expected bdry:  ") + expectedBoundary + " = " + dateToString(expectedBoundary));
274     else
275         errln(UnicodeString("FAIL: Expected bdry:  ") + expectedBoundary + " = " + dateToString(expectedBoundary));
276 }
277 
278 const UDate TimeZoneTest::INTERVAL = 100;
279 
280 // ---------------------------------------------------------------------------------
281 
282 // -------------------------------------
283 
284 /**
285  * Test the offset of the PRT timezone.
286  */
287 void
TestPRTOffset()288 TimeZoneTest::TestPRTOffset()
289 {
290     TimeZone* tz = TimeZone::createTimeZone("PRT");
291     if (tz == 0) {
292         errln("FAIL: TimeZone(PRT) is null");
293     }
294     else {
295       int32_t expectedHour = -4;
296       double expectedOffset = (((double)expectedHour) * millisPerHour);
297       double foundOffset = tz->getRawOffset();
298       int32_t foundHour = (int32_t)foundOffset / millisPerHour;
299       if (expectedOffset != foundOffset) {
300         errln("FAIL: Offset for PRT should be %d, found %d", expectedHour, foundHour);
301       } else {
302         logln("PASS: Offset for PRT should be %d, found %d", expectedHour, foundHour);
303       }
304     }
305     delete tz;
306 }
307 
308 // -------------------------------------
309 
310 /**
311  * Regress a specific bug with a sequence of API calls.
312  */
313 void
TestVariousAPI518()314 TimeZoneTest::TestVariousAPI518()
315 {
316     UErrorCode status = U_ZERO_ERROR;
317     TimeZone* time_zone = TimeZone::createTimeZone("PST");
318     UDate d = date(97, UCAL_APRIL, 30);
319     UnicodeString str;
320     logln("The timezone is " + time_zone->getID(str));
321     if (!time_zone->inDaylightTime(d, status)) errln("FAIL: inDaylightTime returned FALSE");
322     if (U_FAILURE(status)) { errln("FAIL: TimeZone::inDaylightTime failed"); return; }
323     if (!time_zone->useDaylightTime()) errln("FAIL: useDaylightTime returned FALSE");
324     if (time_zone->getRawOffset() != - 8 * millisPerHour) errln("FAIL: getRawOffset returned wrong value");
325     GregorianCalendar *gc = new GregorianCalendar(status);
326     if (U_FAILURE(status)) { errln("FAIL: Couldn't create GregorianCalendar"); return; }
327     gc->setTime(d, status);
328     if (U_FAILURE(status)) { errln("FAIL: GregorianCalendar::setTime failed"); return; }
329     if (time_zone->getOffset(gc->AD, gc->get(UCAL_YEAR, status), gc->get(UCAL_MONTH, status),
330         gc->get(UCAL_DATE, status), (uint8_t)gc->get(UCAL_DAY_OF_WEEK, status), 0, status) != - 7 * millisPerHour)
331         errln("FAIL: getOffset returned wrong value");
332     if (U_FAILURE(status)) { errln("FAIL: GregorianCalendar::set failed"); return; }
333     delete gc;
334     delete time_zone;
335 }
336 
337 // -------------------------------------
338 
339 /**
340  * Test the call which retrieves the available IDs.
341  */
342 void
TestGetAvailableIDs913()343 TimeZoneTest::TestGetAvailableIDs913()
344 {
345     UErrorCode ec = U_ZERO_ERROR;
346     int32_t i;
347 
348 #ifdef U_USE_TIMEZONE_OBSOLETE_2_8
349     // Test legacy API -- remove these tests when the corresponding API goes away (duh)
350     int32_t numIDs = -1;
351     const UnicodeString** ids = TimeZone::createAvailableIDs(numIDs);
352     if (ids == 0 || numIDs < 1) {
353         errln("FAIL: createAvailableIDs()");
354     } else {
355         UnicodeString buf("TimeZone::createAvailableIDs() = { ");
356         for(i=0; i<numIDs; ++i) {
357             if (i) buf.append(", ");
358             buf.append(*ids[i]);
359         }
360         buf.append(" } ");
361         logln(buf + numIDs);
362         // we own the array; the caller owns the contained strings (yuck)
363         uprv_free(ids);
364     }
365 
366     numIDs = -1;
367     ids = TimeZone::createAvailableIDs(-8*U_MILLIS_PER_HOUR, numIDs);
368     if (ids == 0 || numIDs < 1) {
369         errln("FAIL: createAvailableIDs(-8:00)");
370     } else {
371         UnicodeString buf("TimeZone::createAvailableIDs(-8:00) = { ");
372         for(i=0; i<numIDs; ++i) {
373             if (i) buf.append(", ");
374             buf.append(*ids[i]);
375         }
376         buf.append(" } ");
377         logln(buf + numIDs);
378         // we own the array; the caller owns the contained strings (yuck)
379         uprv_free(ids);
380     }
381     numIDs = -1;
382     ids = TimeZone::createAvailableIDs("US", numIDs);
383     if (ids == 0 || numIDs < 1) {
384       errln("FAIL: createAvailableIDs(US) ids=%d, numIDs=%d", ids, numIDs);
385     } else {
386         UnicodeString buf("TimeZone::createAvailableIDs(US) = { ");
387         for(i=0; i<numIDs; ++i) {
388             if (i) buf.append(", ");
389             buf.append(*ids[i]);
390         }
391         buf.append(" } ");
392         logln(buf + numIDs);
393         // we own the array; the caller owns the contained strings (yuck)
394         uprv_free(ids);
395     }
396 #endif
397 
398     UnicodeString str;
399     UnicodeString *buf = new UnicodeString("TimeZone::createEnumeration() = { ");
400     int32_t s_length;
401     StringEnumeration* s = TimeZone::createEnumeration();
402     s_length = s->count(ec);
403     for (i = 0; i < s_length;++i) {
404         if (i > 0) *buf += ", ";
405         if ((i & 1) == 0) {
406             *buf += *s->snext(ec);
407         } else {
408             *buf += UnicodeString(s->next(NULL, ec), "");
409         }
410 
411         if((i % 5) == 4) {
412             // replace s with a clone of itself
413             StringEnumeration *s2 = s->clone();
414             if(s2 == NULL || s_length != s2->count(ec)) {
415                 errln("TimezoneEnumeration.clone() failed");
416             } else {
417                 delete s;
418                 s = s2;
419             }
420         }
421     }
422     *buf += " };";
423     logln(*buf);
424 
425     /* Confirm that the following zones can be retrieved: The first
426      * zone, the last zone, and one in-between.  This tests the binary
427      * search through the system zone data.
428      */
429     s->reset(ec);
430     int32_t middle = s_length/2;
431     for (i=0; i<s_length; ++i) {
432         const UnicodeString* id = s->snext(ec);
433         if (i==0 || i==middle || i==(s_length-1)) {
434         TimeZone *z = TimeZone::createTimeZone(*id);
435         if (z == 0) {
436             errln(UnicodeString("FAIL: createTimeZone(") +
437                   *id + ") -> 0");
438         } else if (z->getID(str) != *id) {
439             errln(UnicodeString("FAIL: createTimeZone(") +
440                   *id + ") -> zone " + str);
441         } else {
442             logln(UnicodeString("OK: createTimeZone(") +
443                   *id + ") succeeded");
444         }
445         delete z;
446         }
447     }
448     delete s;
449 
450     buf->truncate(0);
451     *buf += "TimeZone::createEnumeration(GMT+01:00) = { ";
452 
453     s = TimeZone::createEnumeration(1 * U_MILLIS_PER_HOUR);
454     s_length = s->count(ec);
455     for (i = 0; i < s_length;++i) {
456         if (i > 0) *buf += ", ";
457         *buf += *s->snext(ec);
458     }
459     delete s;
460     *buf += " };";
461     logln(*buf);
462 
463 
464     buf->truncate(0);
465     *buf += "TimeZone::createEnumeration(US) = { ";
466 
467     s = TimeZone::createEnumeration("US");
468     s_length = s->count(ec);
469     for (i = 0; i < s_length;++i) {
470         if (i > 0) *buf += ", ";
471         *buf += *s->snext(ec);
472     }
473     *buf += " };";
474     logln(*buf);
475 
476     TimeZone *tz = TimeZone::createTimeZone("PST");
477     if (tz != 0) logln("getTimeZone(PST) = " + tz->getID(str));
478     else errln("FAIL: getTimeZone(PST) = null");
479     delete tz;
480     tz = TimeZone::createTimeZone("America/Los_Angeles");
481     if (tz != 0) logln("getTimeZone(America/Los_Angeles) = " + tz->getID(str));
482     else errln("FAIL: getTimeZone(PST) = null");
483     delete tz;
484 
485     // @bug 4096694
486     tz = TimeZone::createTimeZone("NON_EXISTENT");
487     UnicodeString temp;
488     if (tz == 0)
489         errln("FAIL: getTimeZone(NON_EXISTENT) = null");
490     else if (tz->getID(temp) != "GMT")
491         errln("FAIL: getTimeZone(NON_EXISTENT) = " + temp);
492     delete tz;
493 
494     delete buf;
495     delete s;
496 }
497 
498 
499 /**
500  * NOTE: As of ICU 2.8, this test confirms that the "tz.alias"
501  * file, used to build ICU alias zones, is working.  It also
502  * looks at some genuine Olson compatibility IDs. [aliu]
503  *
504  * This test is problematic. It should really just confirm that
505  * the list of compatibility zone IDs exist and are somewhat
506  * meaningful (that is, they aren't all aliases of GMT). It goes a
507  * bit further -- it hard-codes expectations about zone behavior,
508  * when in fact zones are redefined quite frequently. ICU's build
509  * process means that it is easy to update ICU to contain the
510  * latest Olson zone data, but if a zone tested here changes, then
511  * this test will fail.  I have updated the test for 1999j data,
512  * but further updates will probably be required. Note that some
513  * of the concerts listed below no longer apply -- in particular,
514  * we do NOT overwrite real UNIX zones with 3-letter IDs. There
515  * are two points of overlap as of 1999j: MET and EET. These are
516  * both real UNIX zones, so we just use the official
517  * definition. This test has been updated to reflect this.
518  * 12/3/99 aliu
519  *
520  * Added tests for additional zones and aliases from the icuzones file.
521  * Markus Scherer 2006-nov-06
522  *
523  * [srl - from java - 7/5/1998]
524  * @bug 4130885
525  * Certain short zone IDs, used since 1.1.x, are incorrect.
526  *
527  * The worst of these is:
528  *
529  * "CAT" (Central African Time) should be GMT+2:00, but instead returns a
530  * zone at GMT-1:00. The zone at GMT-1:00 should be called EGT, CVT, EGST,
531  * or AZOST, depending on which zone is meant, but in no case is it CAT.
532  *
533  * Other wrong zone IDs:
534  *
535  * ECT (European Central Time) GMT+1:00: ECT is Ecuador Time,
536  * GMT-5:00. European Central time is abbreviated CEST.
537  *
538  * SST (Solomon Island Time) GMT+11:00. SST is actually Samoa Standard Time,
539  * GMT-11:00. Solomon Island time is SBT.
540  *
541  * NST (New Zealand Time) GMT+12:00. NST is the abbreviation for
542  * Newfoundland Standard Time, GMT-3:30. New Zealanders use NZST.
543  *
544  * AST (Alaska Standard Time) GMT-9:00. [This has already been noted in
545  * another bug.] It should be "AKST". AST is Atlantic Standard Time,
546  * GMT-4:00.
547  *
548  * PNT (Phoenix Time) GMT-7:00. PNT usually means Pitcairn Time,
549  * GMT-8:30. There is no standard abbreviation for Phoenix time, as distinct
550  * from MST with daylight savings.
551  *
552  * In addition to these problems, a number of zones are FAKE. That is, they
553  * don't match what people use in the real world.
554  *
555  * FAKE zones:
556  *
557  * EET (should be EEST)
558  * ART (should be EEST)
559  * MET (should be IRST)
560  * NET (should be AMST)
561  * PLT (should be PKT)
562  * BST (should be BDT)
563  * VST (should be ICT)
564  * CTT (should be CST) +
565  * ACT (should be CST) +
566  * AET (should be EST) +
567  * MIT (should be WST) +
568  * IET (should be EST) +
569  * PRT (should be AST) +
570  * CNT (should be NST)
571  * AGT (should be ARST)
572  * BET (should be EST) +
573  *
574  * + A zone with the correct name already exists and means something
575  * else. E.g., EST usually indicates the US Eastern zone, so it cannot be
576  * used for Brazil (BET).
577  */
TestShortZoneIDs()578 void TimeZoneTest::TestShortZoneIDs()
579 {
580     int32_t i;
581     // Create a small struct to hold the array
582     struct
583     {
584         const char *id;
585         int32_t    offset;
586         UBool      daylight;
587     }
588     kReferenceList [] =
589     {
590         {"MIT", -660, FALSE},
591         {"HST", -600, FALSE},
592         {"AST", -540, TRUE},
593         {"PST", -480, TRUE},
594         {"PNT", -420, FALSE},
595         {"MST", -420, FALSE}, // updated Aug 2003 aliu
596         {"CST", -360, TRUE},
597         {"IET", -300, TRUE},  // updated Jan 2006 srl
598         {"EST", -300, FALSE}, // updated Aug 2003 aliu
599         {"PRT", -240, FALSE},
600         {"CNT", -210, TRUE},
601         {"AGT", -180, FALSE}, // updated 26 Sep 2000 aliu
602         {"BET", -180, TRUE},
603         // "CAT", -60, FALSE, // Wrong:
604         // As of bug 4130885, fix CAT (Central Africa)
605         {"CAT", 120, FALSE}, // Africa/Harare
606         {"GMT", 0, FALSE},
607         {"UTC", 0, FALSE}, // ** srl: seems broken in C++
608         {"ECT", 60, TRUE},
609         {"ART", 120, TRUE},
610         {"EET", 120, TRUE},
611         {"EAT", 180, FALSE},
612         {"MET", 60, TRUE}, // updated 12/3/99 aliu
613         {"NET", 240, TRUE}, // updated 12/3/99 aliu
614         {"PLT", 300, FALSE}, // updated Aug 2003 aliu
615         {"IST", 330, FALSE},
616         {"BST", 360, FALSE},
617         {"VST", 420, FALSE},
618         {"CTT", 480, FALSE}, // updated Aug 2003 aliu
619         {"JST", 540, FALSE},
620         {"ACT", 570, FALSE}, // updated Aug 2003 aliu
621         {"AET", 600, TRUE},
622         {"SST", 660, FALSE},
623         // "NST", 720, FALSE,
624         // As of bug 4130885, fix NST (New Zealand)
625         {"NST", 720, TRUE}, // Pacific/Auckland
626 
627         // From icuzones:
628         {"Etc/Unknown", 0, FALSE},
629 
630         {"SystemV/AST4ADT", -240, TRUE},
631         {"SystemV/EST5EDT", -300, TRUE},
632         {"SystemV/CST6CDT", -360, TRUE},
633         {"SystemV/MST7MDT", -420, TRUE},
634         {"SystemV/PST8PDT", -480, TRUE},
635         {"SystemV/YST9YDT", -540, TRUE},
636         {"SystemV/AST4", -240, FALSE},
637         {"SystemV/EST5", -300, FALSE},
638         {"SystemV/CST6", -360, FALSE},
639         {"SystemV/MST7", -420, FALSE},
640         {"SystemV/PST8", -480, FALSE},
641         {"SystemV/YST9", -540, FALSE},
642         {"SystemV/HST10", -600, FALSE},
643 
644         {"",0,FALSE}
645     };
646 
647 
648     for(i=0;kReferenceList[i].id[0];i++) {
649         UnicodeString itsID(kReferenceList[i].id);
650         UBool ok = TRUE;
651         // Check existence.
652         TimeZone *tz = TimeZone::createTimeZone(itsID);
653         if (!tz || (kReferenceList[i].offset != 0 && *tz == *TimeZone::getGMT())) {
654             errln("FAIL: Time Zone " + itsID + " does not exist!");
655             continue;
656         }
657 
658         // Check daylight usage.
659         UBool usesDaylight = tz->useDaylightTime();
660         if (usesDaylight != kReferenceList[i].daylight) {
661             errln("FAIL: Time Zone " + itsID + " use daylight is " +
662                   (usesDaylight?"TRUE":"FALSE") +
663                   " but it should be " +
664                   ((kReferenceList[i].daylight)?"TRUE":"FALSE"));
665             ok = FALSE;
666         }
667 
668         // Check offset
669         int32_t offsetInMinutes = tz->getRawOffset()/60000;
670         if (offsetInMinutes != kReferenceList[i].offset) {
671             errln("FAIL: Time Zone " + itsID + " raw offset is " +
672                   offsetInMinutes +
673                   " but it should be " + kReferenceList[i].offset);
674             ok = FALSE;
675         }
676 
677         if (ok) {
678             logln("OK: " + itsID +
679                   " useDaylightTime() & getRawOffset() as expected");
680         }
681         delete tz;
682     }
683 
684 
685     // OK now test compat
686     logln("Testing for compatibility zones");
687 
688     const char* compatibilityMap[] = {
689         // This list is copied from tz.alias.  If tz.alias
690         // changes, this list must be updated.  Current as of Mar 2007
691         "ACT", "Australia/Darwin",
692         "AET", "Australia/Sydney",
693         "AGT", "America/Buenos_Aires",
694         "ART", "Africa/Cairo",
695         "AST", "America/Anchorage",
696         "BET", "America/Sao_Paulo",
697         "BST", "Asia/Dhaka", // # spelling changed in 2000h; was Asia/Dacca
698         "CAT", "Africa/Harare",
699         "CNT", "America/St_Johns",
700         "CST", "America/Chicago",
701         "CTT", "Asia/Shanghai",
702         "EAT", "Africa/Addis_Ababa",
703         "ECT", "Europe/Paris",
704         // EET Europe/Istanbul # EET is a standard UNIX zone
705         // "EST", "America/New_York", # Defined as -05:00
706         // "HST", "Pacific/Honolulu", # Defined as -10:00
707         "IET", "America/Indianapolis",
708         "IST", "Asia/Calcutta",
709         "JST", "Asia/Tokyo",
710         // MET Asia/Tehran # MET is a standard UNIX zone
711         "MIT", "Pacific/Apia",
712         // "MST", "America/Denver", # Defined as -07:00
713         "NET", "Asia/Yerevan",
714         "NST", "Pacific/Auckland",
715         "PLT", "Asia/Karachi",
716         "PNT", "America/Phoenix",
717         "PRT", "America/Puerto_Rico",
718         "PST", "America/Los_Angeles",
719         "SST", "Pacific/Guadalcanal",
720         "UTC", "Etc/GMT",
721         "VST", "Asia/Saigon",
722          "","",""
723     };
724 
725     for (i=0;*compatibilityMap[i];i+=2) {
726         UnicodeString itsID;
727 
728         const char *zone1 = compatibilityMap[i];
729         const char *zone2 = compatibilityMap[i+1];
730 
731         TimeZone *tz1 = TimeZone::createTimeZone(zone1);
732         TimeZone *tz2 = TimeZone::createTimeZone(zone2);
733 
734         if (!tz1) {
735             errln(UnicodeString("FAIL: Could not find short ID zone ") + zone1);
736         }
737         if (!tz2) {
738             errln(UnicodeString("FAIL: Could not find long ID zone ") + zone2);
739         }
740 
741         if (tz1 && tz2) {
742             // make NAME same so comparison will only look at the rest
743             tz2->setID(tz1->getID(itsID));
744 
745             if (*tz1 != *tz2) {
746                 errln("FAIL: " + UnicodeString(zone1) +
747                       " != " + UnicodeString(zone2));
748             } else {
749                 logln("OK: " + UnicodeString(zone1) +
750                       " == " + UnicodeString(zone2));
751             }
752         }
753 
754         delete tz1;
755         delete tz2;
756     }
757 }
758 
759 
760 /**
761  * Utility function for TestCustomParse
762  */
formatOffset(int32_t offset,UnicodeString & rv)763 UnicodeString& TimeZoneTest::formatOffset(int32_t offset, UnicodeString &rv) {
764     rv.remove();
765     UChar sign = 0x002B;
766     if (offset < 0) {
767         sign = 0x002D;
768         offset = -offset;
769     }
770 
771     int32_t s = offset % 60;
772     offset /= 60;
773     int32_t m = offset % 60;
774     int32_t h = offset / 60;
775 
776     rv += (UChar)(sign);
777     if (h >= 10) {
778         rv += (UChar)(0x0030 + (h/10));
779     } else {
780         rv += (UChar)0x0030;
781     }
782     rv += (UChar)(0x0030 + (h%10));
783 
784     rv += (UChar)0x003A; /* ':' */
785     if (m >= 10) {
786         rv += (UChar)(0x0030 + (m/10));
787     } else {
788         rv += (UChar)0x0030;
789     }
790     rv += (UChar)(0x0030 + (m%10));
791 
792     if (s) {
793         rv += (UChar)0x003A; /* ':' */
794         if (s >= 10) {
795             rv += (UChar)(0x0030 + (s/10));
796         } else {
797             rv += (UChar)0x0030;
798         }
799         rv += (UChar)(0x0030 + (s%10));
800     }
801     return rv;
802 }
803 
804 /**
805  * Utility function for TestCustomParse, generating time zone ID
806  * string for the give offset.
807  */
formatTZID(int32_t offset,UnicodeString & rv)808 UnicodeString& TimeZoneTest::formatTZID(int32_t offset, UnicodeString &rv) {
809     rv.remove();
810     UChar sign = 0x002B;
811     if (offset < 0) {
812         sign = 0x002D;
813         offset = -offset;
814     }
815 
816     int32_t s = offset % 60;
817     offset /= 60;
818     int32_t m = offset % 60;
819     int32_t h = offset / 60;
820 
821     rv += "GMT";
822     rv += (UChar)(sign);
823     if (h >= 10) {
824         rv += (UChar)(0x0030 + (h/10));
825     } else {
826         rv += (UChar)0x0030;
827     }
828     rv += (UChar)(0x0030 + (h%10));
829 
830     if (m >= 10) {
831         rv += (UChar)(0x0030 + (m/10));
832     } else {
833         rv += (UChar)0x0030;
834     }
835     rv += (UChar)(0x0030 + (m%10));
836 
837     if (s) {
838         if (s >= 10) {
839             rv += (UChar)(0x0030 + (s/10));
840         } else {
841             rv += (UChar)0x0030;
842         }
843         rv += (UChar)(0x0030 + (s%10));
844     }
845     return rv;
846 }
847 
848 /**
849  * As part of the VM fix (see CCC approved RFE 4028006, bug
850  * 4044013), TimeZone.getTimeZone() has been modified to recognize
851  * generic IDs of the form GMT[+-]hh:mm, GMT[+-]hhmm, and
852  * GMT[+-]hh.  Test this behavior here.
853  *
854  * @bug 4044013
855  */
TestCustomParse()856 void TimeZoneTest::TestCustomParse()
857 {
858     int32_t i;
859     const int32_t kUnparseable = 604800; // the number of seconds in a week. More than any offset should be.
860 
861     struct
862     {
863         const char *customId;
864         int32_t expectedOffset;
865     }
866     kData[] =
867     {
868         // ID        Expected offset in seconds
869         {"GMT",       kUnparseable},   //Isn't custom. [returns normal GMT]
870         {"GMT-YOUR.AD.HERE", kUnparseable},
871         {"GMT0",      kUnparseable},
872         {"GMT+0",     (0)},
873         {"GMT+1",     (1*60*60)},
874         {"GMT-0030",  (-30*60)},
875         {"GMT+15:99", kUnparseable},
876         {"GMT+",      kUnparseable},
877         {"GMT-",      kUnparseable},
878         {"GMT+0:",    kUnparseable},
879         {"GMT-:",     kUnparseable},
880         {"GMT-YOUR.AD.HERE",    kUnparseable},
881         {"GMT+0010",  (10*60)}, // Interpret this as 00:10
882         {"GMT-10",    (-10*60*60)},
883         {"GMT+30",    kUnparseable},
884         {"GMT-3:30",  (-(3*60+30)*60)},
885         {"GMT-230",   (-(2*60+30)*60)},
886         {"GMT+05:13:05",    ((5*60+13)*60+5)},
887         {"GMT-71023",       (-((7*60+10)*60+23))},
888         {"GMT+01:23:45:67", kUnparseable},
889         {"GMT+01:234",      kUnparseable},
890         {"GMT-2:31:123",    kUnparseable},
891         {"GMT+3:75",        kUnparseable},
892         {"GMT-01010101",    kUnparseable},
893         {0,           0}
894     };
895 
896     for (i=0; kData[i].customId != 0; i++) {
897         UnicodeString id(kData[i].customId);
898         int32_t exp = kData[i].expectedOffset;
899         TimeZone *zone = TimeZone::createTimeZone(id);
900         UnicodeString   itsID, temp;
901 
902         if (zone->getDynamicClassID() == OlsonTimeZone::getStaticClassID()) {
903             logln(id + " -> Olson time zone");
904         } else {
905             zone->getID(itsID);
906             int32_t ioffset = zone->getRawOffset()/1000;
907             UnicodeString offset, expectedID;
908             formatOffset(ioffset, offset);
909             formatTZID(ioffset, expectedID);
910             logln(id + " -> " + itsID + " " + offset);
911             if (exp == kUnparseable && itsID != "GMT") {
912                 errln("Expected parse failure for " + id +
913                       ", got offset of " + offset +
914                       ", id " + itsID);
915             }
916             // JDK 1.3 creates custom zones with the ID "Custom"
917             // JDK 1.4 creates custom zones with IDs of the form "GMT+02:00"
918             // ICU creates custom zones with IDs of the form "GMT+0200"
919             else if (exp != kUnparseable && (ioffset != exp || itsID != expectedID)) {
920                 errln("Expected offset of " + formatOffset(exp, temp) +
921                       ", id " + expectedID +
922                       ", for " + id +
923                       ", got offset of " + offset +
924                       ", id " + itsID);
925             }
926         }
927         delete zone;
928     }
929 }
930 
931 void
TestAliasedNames()932 TimeZoneTest::TestAliasedNames()
933 {
934     struct {
935         const char *from;
936         const char *to;
937     } kData[] = {
938         /* Generated by org.unicode.cldr.tool.CountItems */
939 
940         /* zoneID, canonical zoneID */
941         {"Africa/Timbuktu", "Africa/Bamako"},
942         {"America/Argentina/Buenos_Aires", "America/Buenos_Aires"},
943         {"America/Argentina/Catamarca", "America/Catamarca"},
944         {"America/Argentina/ComodRivadavia", "America/Catamarca"},
945         {"America/Argentina/Cordoba", "America/Cordoba"},
946         {"America/Argentina/Jujuy", "America/Jujuy"},
947         {"America/Argentina/Mendoza", "America/Mendoza"},
948         {"America/Atka", "America/Adak"},
949         {"America/Ensenada", "America/Tijuana"},
950         {"America/Fort_Wayne", "America/Indiana/Indianapolis"},
951         {"America/Indianapolis", "America/Indiana/Indianapolis"},
952         {"America/Knox_IN", "America/Indiana/Knox"},
953         {"America/Louisville", "America/Kentucky/Louisville"},
954         {"America/Porto_Acre", "America/Rio_Branco"},
955         {"America/Rosario", "America/Cordoba"},
956         {"America/Virgin", "America/St_Thomas"},
957         {"Asia/Ashkhabad", "Asia/Ashgabat"},
958         {"Asia/Chungking", "Asia/Chongqing"},
959         {"Asia/Dacca", "Asia/Dhaka"},
960         {"Asia/Istanbul", "Europe/Istanbul"},
961         {"Asia/Macao", "Asia/Macau"},
962         {"Asia/Tel_Aviv", "Asia/Jerusalem"},
963         {"Asia/Thimbu", "Asia/Thimphu"},
964         {"Asia/Ujung_Pandang", "Asia/Makassar"},
965         {"Asia/Ulan_Bator", "Asia/Ulaanbaatar"},
966         {"Australia/ACT", "Australia/Sydney"},
967         {"Australia/Canberra", "Australia/Sydney"},
968         {"Australia/LHI", "Australia/Lord_Howe"},
969         {"Australia/NSW", "Australia/Sydney"},
970         {"Australia/North", "Australia/Darwin"},
971         {"Australia/Queensland", "Australia/Brisbane"},
972         {"Australia/South", "Australia/Adelaide"},
973         {"Australia/Tasmania", "Australia/Hobart"},
974         {"Australia/Victoria", "Australia/Melbourne"},
975         {"Australia/West", "Australia/Perth"},
976         {"Australia/Yancowinna", "Australia/Broken_Hill"},
977         {"Brazil/Acre", "America/Rio_Branco"},
978         {"Brazil/DeNoronha", "America/Noronha"},
979         {"Brazil/East", "America/Sao_Paulo"},
980         {"Brazil/West", "America/Manaus"},
981         {"Canada/Atlantic", "America/Halifax"},
982         {"Canada/Central", "America/Winnipeg"},
983         {"Canada/East-Saskatchewan", "America/Regina"},
984         {"Canada/Eastern", "America/Toronto"},
985         {"Canada/Mountain", "America/Edmonton"},
986         {"Canada/Newfoundland", "America/St_Johns"},
987         {"Canada/Pacific", "America/Vancouver"},
988         {"Canada/Saskatchewan", "America/Regina"},
989         {"Canada/Yukon", "America/Whitehorse"},
990         {"Chile/Continental", "America/Santiago"},
991         {"Chile/EasterIsland", "Pacific/Easter"},
992         {"Cuba", "America/Havana"},
993         {"Egypt", "Africa/Cairo"},
994         {"Eire", "Europe/Dublin"},
995         {"Etc/GMT+0", "Etc/GMT"},
996         {"Etc/GMT-0", "Etc/GMT"},
997         {"Etc/GMT0", "Etc/GMT"},
998         {"Etc/Greenwich", "Etc/GMT"},
999         {"Etc/UCT", "Etc/GMT"},
1000         {"Etc/UTC", "Etc/GMT"},
1001         {"Etc/Universal", "Etc/GMT"},
1002         {"Etc/Zulu", "Etc/GMT"},
1003         {"Europe/Belfast", "Europe/London"},
1004         {"Europe/Nicosia", "Asia/Nicosia"},
1005         {"Europe/Tiraspol", "Europe/Chisinau"},
1006         {"GB", "Europe/London"},
1007         {"GB-Eire", "Europe/London"},
1008         {"GMT", "Etc/GMT"},
1009         {"GMT+0", "Etc/GMT"},
1010         {"GMT-0", "Etc/GMT"},
1011         {"GMT0", "Etc/GMT"},
1012         {"Greenwich", "Etc/GMT"},
1013         {"Hongkong", "Asia/Hong_Kong"},
1014         {"Iceland", "Atlantic/Reykjavik"},
1015         {"Iran", "Asia/Tehran"},
1016         {"Israel", "Asia/Jerusalem"},
1017         {"Jamaica", "America/Jamaica"},
1018         {"Japan", "Asia/Tokyo"},
1019         {"Kwajalein", "Pacific/Kwajalein"},
1020         {"Libya", "Africa/Tripoli"},
1021         {"Mexico/BajaNorte", "America/Tijuana"},
1022         {"Mexico/BajaSur", "America/Mazatlan"},
1023         {"Mexico/General", "America/Mexico_City"},
1024         {"NZ", "Pacific/Auckland"},
1025         {"NZ-CHAT", "Pacific/Chatham"},
1026         {"Navajo", "America/Shiprock"},
1027         {"PRC", "Asia/Shanghai"},
1028         {"Pacific/Samoa", "Pacific/Pago_Pago"},
1029         {"Pacific/Yap", "Pacific/Truk"},
1030         {"Poland", "Europe/Warsaw"},
1031         {"Portugal", "Europe/Lisbon"},
1032         {"ROC", "Asia/Taipei"},
1033         {"ROK", "Asia/Seoul"},
1034         {"Singapore", "Asia/Singapore"},
1035         {"Turkey", "Europe/Istanbul"},
1036         {"UCT", "Etc/GMT"},
1037         {"US/Alaska", "America/Anchorage"},
1038         {"US/Aleutian", "America/Adak"},
1039         {"US/Arizona", "America/Phoenix"},
1040         {"US/Central", "America/Chicago"},
1041         {"US/East-Indiana", "America/Indiana/Indianapolis"},
1042         {"US/Eastern", "America/New_York"},
1043         {"US/Hawaii", "Pacific/Honolulu"},
1044         {"US/Indiana-Starke", "America/Indiana/Knox"},
1045         {"US/Michigan", "America/Detroit"},
1046         {"US/Mountain", "America/Denver"},
1047         {"US/Pacific", "America/Los_Angeles"},
1048         {"US/Pacific-New", "America/Los_Angeles"},
1049         {"US/Samoa", "Pacific/Pago_Pago"},
1050         {"UTC", "Etc/GMT"},
1051         {"Universal", "Etc/GMT"},
1052         {"W-SU", "Europe/Moscow"},
1053         {"Zulu", "Etc/GMT"},
1054         /* Total: 113 */
1055 
1056     };
1057 
1058     TimeZone::EDisplayType styles[] = { TimeZone::SHORT, TimeZone::LONG };
1059     UBool useDst[] = { FALSE, TRUE };
1060     int32_t noLoc = uloc_countAvailable();
1061 
1062     int32_t i, j, k, loc;
1063     UnicodeString fromName, toName;
1064     TimeZone *from = NULL, *to = NULL;
1065     for(i = 0; i < (int32_t)(sizeof(kData)/sizeof(kData[0])); i++) {
1066         from = TimeZone::createTimeZone(kData[i].from);
1067         to = TimeZone::createTimeZone(kData[i].to);
1068         if(!from->hasSameRules(*to)) {
1069             errln("different at %i\n", i);
1070         }
1071         if(!quick) {
1072             for(loc = 0; loc < noLoc; loc++) {
1073                 const char* locale = uloc_getAvailable(loc);
1074                 for(j = 0; j < (int32_t)(sizeof(styles)/sizeof(styles[0])); j++) {
1075                     for(k = 0; k < (int32_t)(sizeof(useDst)/sizeof(useDst[0])); k++) {
1076                         fromName.remove();
1077                         toName.remove();
1078                         from->getDisplayName(useDst[k], styles[j],locale, fromName);
1079                         to->getDisplayName(useDst[k], styles[j], locale, toName);
1080                         if(fromName.compare(toName) != 0) {
1081                             errln("Fail: Expected "+toName+" but got " + prettify(fromName)
1082                                 + " for locale: " + locale + " index: "+ loc
1083                                 + " to id "+ kData[i].to
1084                                 + " from id " + kData[i].from);
1085                         }
1086                     }
1087                 }
1088             }
1089         } else {
1090             fromName.remove();
1091             toName.remove();
1092             from->getDisplayName(fromName);
1093             to->getDisplayName(toName);
1094             if(fromName.compare(toName) != 0) {
1095                 errln("Fail: Expected "+toName+" but got " + fromName);
1096             }
1097         }
1098         delete from;
1099         delete to;
1100     }
1101 }
1102 
1103 /**
1104  * Test the basic functionality of the getDisplayName() API.
1105  *
1106  * @bug 4112869
1107  * @bug 4028006
1108  *
1109  * See also API change request A41.
1110  *
1111  * 4/21/98 - make smarter, so the test works if the ext resources
1112  * are present or not.
1113  */
1114 void
TestDisplayName()1115 TimeZoneTest::TestDisplayName()
1116 {
1117     UErrorCode status = U_ZERO_ERROR;
1118     int32_t i;
1119     TimeZone *zone = TimeZone::createTimeZone("PST");
1120     UnicodeString name;
1121     zone->getDisplayName(Locale::getEnglish(), name);
1122     logln("PST->" + name);
1123     if (name.compare("Pacific Standard Time") != 0)
1124         errln("Fail: Expected \"Pacific Standard Time\" but got " + name);
1125 
1126     //*****************************************************************
1127     // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES
1128     // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES
1129     // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES
1130     //*****************************************************************
1131     struct
1132     {
1133         UBool useDst;
1134         TimeZone::EDisplayType style;
1135         const char *expect;
1136     } kData[] = {
1137         {FALSE, TimeZone::SHORT, "PST"},
1138         {TRUE,  TimeZone::SHORT, "PDT"},
1139         {FALSE, TimeZone::LONG,  "Pacific Standard Time"},
1140         {TRUE,  TimeZone::LONG,  "Pacific Daylight Time"},
1141 
1142         {FALSE, TimeZone::LONG, ""}
1143     };
1144 
1145     for (i=0; kData[i].expect[0] != '\0'; i++)
1146     {
1147         name.remove();
1148         name = zone->getDisplayName(kData[i].useDst,
1149                                    kData[i].style,
1150                                    Locale::getEnglish(), name);
1151         if (name.compare(kData[i].expect) != 0)
1152             errln("Fail: Expected " + UnicodeString(kData[i].expect) + "; got " + name);
1153         logln("PST [with options]->" + name);
1154     }
1155     for (i=0; kData[i].expect[0] != '\0'; i++)
1156     {
1157         name.remove();
1158         name = zone->getDisplayName(kData[i].useDst,
1159                                    kData[i].style, name);
1160         if (name.compare(kData[i].expect) != 0)
1161             errln("Fail: Expected " + UnicodeString(kData[i].expect) + "; got " + name);
1162         logln("PST [with options]->" + name);
1163     }
1164 
1165 
1166     // Make sure that we don't display the DST name by constructing a fake
1167     // PST zone that has DST all year long.
1168     SimpleTimeZone *zone2 = new SimpleTimeZone(0, "PST");
1169 
1170     zone2->setStartRule(UCAL_JANUARY, 1, 0, 0, status);
1171     zone2->setEndRule(UCAL_DECEMBER, 31, 0, 0, status);
1172 
1173     UnicodeString inDaylight;
1174     if (zone2->inDaylightTime(UDate(0), status)) {
1175         inDaylight = UnicodeString("TRUE");
1176     } else {
1177         inDaylight = UnicodeString("FALSE");
1178     }
1179     logln(UnicodeString("Modified PST inDaylightTime->") + inDaylight );
1180     if(U_FAILURE(status))
1181     {
1182         errln("Some sort of error..." + UnicodeString(u_errorName(status))); // REVISIT
1183     }
1184     name.remove();
1185     name = zone2->getDisplayName(Locale::getEnglish(),name);
1186     logln("Modified PST->" + name);
1187     if (name.compare("Pacific Standard Time") != 0)
1188         errln("Fail: Expected \"Pacific Standard Time\"");
1189 
1190     // Make sure we get the default display format for Locales
1191     // with no display name data.
1192     Locale mt_MT("mt_MT");
1193     name.remove();
1194     name = zone->getDisplayName(mt_MT,name);
1195     //*****************************************************************
1196     // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES
1197     // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES
1198     // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES
1199     //*****************************************************************
1200     logln("PST(mt_MT)->" + name);
1201 
1202     // *** REVISIT SRL how in the world do I check this? looks java specific.
1203     // Now be smart -- check to see if zh resource is even present.
1204     // If not, we expect the en fallback behavior.
1205     ResourceBundle enRB(NULL,
1206                             Locale::getEnglish(), status);
1207     if(U_FAILURE(status))
1208         errln("Couldn't get ResourceBundle for en");
1209 
1210     ResourceBundle mtRB(NULL,
1211                          mt_MT, status);
1212     //if(U_FAILURE(status))
1213     //    errln("Couldn't get ResourceBundle for mt_MT");
1214 
1215     UBool noZH = U_FAILURE(status);
1216 
1217     if (noZH) {
1218         logln("Warning: Not testing the mt_MT behavior because resource is absent");
1219         if (name != "Pacific Standard Time")
1220             errln("Fail: Expected Pacific Standard Time");
1221     }
1222 
1223 
1224     if      (name.compare("GMT-08:00") &&
1225              name.compare("GMT-8:00") &&
1226              name.compare("GMT-0800") &&
1227              name.compare("GMT-800")) {
1228       errln(UnicodeString("Fail: Expected GMT-08:00 or something similar for PST in mt_MT but got ") + name );
1229         errln("************************************************************");
1230         errln("THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED");
1231         errln("************************************************************");
1232     }
1233 
1234     // Now try a non-existent zone
1235     delete zone2;
1236     zone2 = new SimpleTimeZone(90*60*1000, "xyzzy");
1237     name.remove();
1238     name = zone2->getDisplayName(Locale::getEnglish(),name);
1239     logln("GMT+90min->" + name);
1240     if (name.compare("GMT+01:30") &&
1241         name.compare("GMT+1:30") &&
1242         name.compare("GMT+0130") &&
1243         name.compare("GMT+130"))
1244         errln("Fail: Expected GMT+01:30 or something similar");
1245     name.truncate(0);
1246     zone2->getDisplayName(name);
1247     logln("GMT+90min->" + name);
1248     if (name.compare("GMT+01:30") &&
1249         name.compare("GMT+1:30") &&
1250         name.compare("GMT+0130") &&
1251         name.compare("GMT+130"))
1252         errln("Fail: Expected GMT+01:30 or something similar");
1253     // clean up
1254     delete zone;
1255     delete zone2;
1256 }
1257 
1258 /**
1259  * @bug 4107276
1260  */
1261 void
TestDSTSavings()1262 TimeZoneTest::TestDSTSavings()
1263 {
1264     UErrorCode status = U_ZERO_ERROR;
1265     // It might be better to find a way to integrate this test into the main TimeZone
1266     // tests above, but I don't have time to figure out how to do this (or if it's
1267     // even really a good idea).  Let's consider that a future.  --rtg 1/27/98
1268     SimpleTimeZone *tz = new SimpleTimeZone(-5 * U_MILLIS_PER_HOUR, "dstSavingsTest",
1269                                            UCAL_MARCH, 1, 0, 0, UCAL_SEPTEMBER, 1, 0, 0,
1270                                            (int32_t)(0.5 * U_MILLIS_PER_HOUR), status);
1271     if(U_FAILURE(status))
1272         errln("couldn't create TimeZone");
1273 
1274     if (tz->getRawOffset() != -5 * U_MILLIS_PER_HOUR)
1275         errln(UnicodeString("Got back a raw offset of ") + (tz->getRawOffset() / U_MILLIS_PER_HOUR) +
1276               " hours instead of -5 hours.");
1277     if (!tz->useDaylightTime())
1278         errln("Test time zone should use DST but claims it doesn't.");
1279     if (tz->getDSTSavings() != 0.5 * U_MILLIS_PER_HOUR)
1280         errln(UnicodeString("Set DST offset to 0.5 hour, but got back ") + (tz->getDSTSavings() /
1281                                                              U_MILLIS_PER_HOUR) + " hours instead.");
1282 
1283     int32_t offset = tz->getOffset(GregorianCalendar::AD, 1998, UCAL_JANUARY, 1,
1284                               UCAL_THURSDAY, 10 * U_MILLIS_PER_HOUR,status);
1285     if (offset != -5 * U_MILLIS_PER_HOUR)
1286         errln(UnicodeString("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got ")
1287               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1288 
1289     offset = tz->getOffset(GregorianCalendar::AD, 1998, UCAL_JUNE, 1, UCAL_MONDAY,
1290                           10 * U_MILLIS_PER_HOUR,status);
1291     if (offset != -4.5 * U_MILLIS_PER_HOUR)
1292         errln(UnicodeString("The offset for 10 AM, 6/1/98 should have been -4.5 hours, but we got ")
1293               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1294 
1295     tz->setDSTSavings(U_MILLIS_PER_HOUR, status);
1296     offset = tz->getOffset(GregorianCalendar::AD, 1998, UCAL_JANUARY, 1,
1297                           UCAL_THURSDAY, 10 * U_MILLIS_PER_HOUR,status);
1298     if (offset != -5 * U_MILLIS_PER_HOUR)
1299         errln(UnicodeString("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got ")
1300               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1301 
1302     offset = tz->getOffset(GregorianCalendar::AD, 1998, UCAL_JUNE, 1, UCAL_MONDAY,
1303                           10 * U_MILLIS_PER_HOUR,status);
1304     if (offset != -4 * U_MILLIS_PER_HOUR)
1305         errln(UnicodeString("The offset for 10 AM, 6/1/98 (with a 1-hour DST offset) should have been -4 hours, but we got ")
1306               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1307 
1308     delete tz;
1309 }
1310 
1311 /**
1312  * @bug 4107570
1313  */
1314 void
TestAlternateRules()1315 TimeZoneTest::TestAlternateRules()
1316 {
1317     // Like TestDSTSavings, this test should probably be integrated somehow with the main
1318     // test at the top of this class, but I didn't have time to figure out how to do that.
1319     //                      --rtg 1/28/98
1320 
1321     SimpleTimeZone tz(-5 * U_MILLIS_PER_HOUR, "alternateRuleTest");
1322 
1323     // test the day-of-month API
1324     UErrorCode status = U_ZERO_ERROR;
1325     tz.setStartRule(UCAL_MARCH, 10, 12 * U_MILLIS_PER_HOUR, status);
1326     if(U_FAILURE(status))
1327         errln("tz.setStartRule failed");
1328     tz.setEndRule(UCAL_OCTOBER, 20, 12 * U_MILLIS_PER_HOUR, status);
1329     if(U_FAILURE(status))
1330         errln("tz.setStartRule failed");
1331 
1332     int32_t offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_MARCH, 5,
1333                               UCAL_THURSDAY, 10 * U_MILLIS_PER_HOUR,status);
1334     if (offset != -5 * U_MILLIS_PER_HOUR)
1335         errln(UnicodeString("The offset for 10AM, 3/5/98 should have been -5 hours, but we got ")
1336               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1337 
1338     offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_MARCH, 15,
1339                           UCAL_SUNDAY, 10 * millisPerHour,status);
1340     if (offset != -4 * U_MILLIS_PER_HOUR)
1341         errln(UnicodeString("The offset for 10AM, 3/15/98 should have been -4 hours, but we got ")
1342               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1343 
1344     offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_OCTOBER, 15,
1345                           UCAL_THURSDAY, 10 * millisPerHour,status);
1346     if (offset != -4 * U_MILLIS_PER_HOUR)
1347         errln(UnicodeString("The offset for 10AM, 10/15/98 should have been -4 hours, but we got ")              + (offset / U_MILLIS_PER_HOUR) + " hours.");
1348 
1349     offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_OCTOBER, 25,
1350                           UCAL_SUNDAY, 10 * millisPerHour,status);
1351     if (offset != -5 * U_MILLIS_PER_HOUR)
1352         errln(UnicodeString("The offset for 10AM, 10/25/98 should have been -5 hours, but we got ")
1353               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1354 
1355     // test the day-of-week-after-day-in-month API
1356     tz.setStartRule(UCAL_MARCH, 10, UCAL_FRIDAY, 12 * millisPerHour, TRUE, status);
1357     if(U_FAILURE(status))
1358         errln("tz.setStartRule failed");
1359     tz.setEndRule(UCAL_OCTOBER, 20, UCAL_FRIDAY, 12 * millisPerHour, FALSE, status);
1360     if(U_FAILURE(status))
1361         errln("tz.setStartRule failed");
1362 
1363     offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_MARCH, 11,
1364                           UCAL_WEDNESDAY, 10 * millisPerHour,status);
1365     if (offset != -5 * U_MILLIS_PER_HOUR)
1366         errln(UnicodeString("The offset for 10AM, 3/11/98 should have been -5 hours, but we got ")
1367               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1368 
1369     offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_MARCH, 14,
1370                           UCAL_SATURDAY, 10 * millisPerHour,status);
1371     if (offset != -4 * U_MILLIS_PER_HOUR)
1372         errln(UnicodeString("The offset for 10AM, 3/14/98 should have been -4 hours, but we got ")
1373               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1374 
1375     offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_OCTOBER, 15,
1376                           UCAL_THURSDAY, 10 * millisPerHour,status);
1377     if (offset != -4 * U_MILLIS_PER_HOUR)
1378         errln(UnicodeString("The offset for 10AM, 10/15/98 should have been -4 hours, but we got ")
1379               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1380 
1381     offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_OCTOBER, 17,
1382                           UCAL_SATURDAY, 10 * millisPerHour,status);
1383     if (offset != -5 * U_MILLIS_PER_HOUR)
1384         errln(UnicodeString("The offset for 10AM, 10/17/98 should have been -5 hours, but we got ")
1385               + (offset / U_MILLIS_PER_HOUR) + " hours.");
1386 }
1387 
TestFractionalDST()1388 void TimeZoneTest::TestFractionalDST() {
1389     const char* tzName = "Australia/Lord_Howe"; // 30 min offset
1390     TimeZone* tz_icu = TimeZone::createTimeZone(tzName);
1391 	int dst_icu = tz_icu->getDSTSavings();
1392     UnicodeString id;
1393     int32_t expected = 1800000;
1394 	if (expected != dst_icu) {
1395 	    errln(UnicodeString("java reports dst savings of ") + expected +
1396 	        " but icu reports " + dst_icu +
1397 	        " for tz " + tz_icu->getID(id));
1398 	} else {
1399 	    logln(UnicodeString("both java and icu report dst savings of ") + expected + " for tz " + tz_icu->getID(id));
1400 	}
1401     delete tz_icu;
1402 }
1403 
1404 /**
1405  * Test country code support.  Jitterbug 776.
1406  */
TestCountries()1407 void TimeZoneTest::TestCountries() {
1408     // Make sure America/Los_Angeles is in the "US" group, and
1409     // Asia/Tokyo isn't.  Vice versa for the "JP" group.
1410     UErrorCode ec = U_ZERO_ERROR;
1411     int32_t n;
1412     StringEnumeration* s = TimeZone::createEnumeration("US");
1413     n = s->count(ec);
1414     UBool la = FALSE, tokyo = FALSE;
1415     UnicodeString laZone("America/Los_Angeles", "");
1416     UnicodeString tokyoZone("Asia/Tokyo", "");
1417     int32_t i;
1418 
1419     if (s == NULL || n <= 0) {
1420         errln("FAIL: TimeZone::createEnumeration() returned nothing");
1421         return;
1422     }
1423     for (i=0; i<n; ++i) {
1424         const UnicodeString* id = s->snext(ec);
1425         if (*id == (laZone)) {
1426             la = TRUE;
1427         }
1428         if (*id == (tokyoZone)) {
1429             tokyo = TRUE;
1430         }
1431     }
1432     if (!la || tokyo) {
1433         errln("FAIL: " + laZone + " in US = " + la);
1434         errln("FAIL: " + tokyoZone + " in US = " + tokyo);
1435     }
1436     delete s;
1437 
1438     s = TimeZone::createEnumeration("JP");
1439     n = s->count(ec);
1440     la = FALSE; tokyo = FALSE;
1441 
1442     for (i=0; i<n; ++i) {
1443         const UnicodeString* id = s->snext(ec);
1444         if (*id == (laZone)) {
1445             la = TRUE;
1446         }
1447         if (*id == (tokyoZone)) {
1448             tokyo = TRUE;
1449         }
1450     }
1451     if (la || !tokyo) {
1452         errln("FAIL: " + laZone + " in JP = " + la);
1453         errln("FAIL: " + tokyoZone + " in JP = " + tokyo);
1454     }
1455     StringEnumeration* s1 = TimeZone::createEnumeration("US");
1456     StringEnumeration* s2 = TimeZone::createEnumeration("US");
1457     for(i=0;i<n;++i){
1458         const UnicodeString* id1 = s1->snext(ec);
1459         if(id1==NULL || U_FAILURE(ec)){
1460             errln("Failed to fetch next from TimeZone enumeration. Length returned : %i Current Index: %i", n,i);
1461         }
1462         TimeZone* tz1 = TimeZone::createTimeZone(*id1);
1463         for(int j=0; j<n;++j){
1464             const UnicodeString* id2 = s2->snext(ec);
1465             if(id2==NULL || U_FAILURE(ec)){
1466                 errln("Failed to fetch next from TimeZone enumeration. Length returned : %i Current Index: %i", n,i);
1467             }
1468             TimeZone* tz2 = TimeZone::createTimeZone(*id2);
1469             if(tz1->hasSameRules(*tz2)){
1470                 logln("ID1 : " + *id1+" == ID2 : " +*id2);
1471             }
1472             delete tz2;
1473         }
1474         delete tz1;
1475     }
1476     delete s1;
1477     delete s2;
1478     delete s;
1479 }
1480 
TestHistorical()1481 void TimeZoneTest::TestHistorical() {
1482     const int32_t H = U_MILLIS_PER_HOUR;
1483     struct {
1484         const char* id;
1485         int32_t time; // epoch seconds
1486         int32_t offset; // total offset (millis)
1487     } DATA[] = {
1488         // Add transition points (before/after) as desired to test historical
1489         // behavior.
1490         {"America/Los_Angeles", 638963999, -8*H}, // Sun Apr 01 01:59:59 GMT-08:00 1990
1491         {"America/Los_Angeles", 638964000, -7*H}, // Sun Apr 01 03:00:00 GMT-07:00 1990
1492         {"America/Los_Angeles", 657104399, -7*H}, // Sun Oct 28 01:59:59 GMT-07:00 1990
1493         {"America/Los_Angeles", 657104400, -8*H}, // Sun Oct 28 01:00:00 GMT-08:00 1990
1494         {"America/Goose_Bay", -116445601, -4*H}, // Sun Apr 24 01:59:59 GMT-04:00 1966
1495         {"America/Goose_Bay", -116445600, -3*H}, // Sun Apr 24 03:00:00 GMT-03:00 1966
1496         {"America/Goose_Bay", -100119601, -3*H}, // Sun Oct 30 01:59:59 GMT-03:00 1966
1497         {"America/Goose_Bay", -100119600, -4*H}, // Sun Oct 30 01:00:00 GMT-04:00 1966
1498         {"America/Goose_Bay", -84391201, -4*H}, // Sun Apr 30 01:59:59 GMT-04:00 1967
1499         {"America/Goose_Bay", -84391200, -3*H}, // Sun Apr 30 03:00:00 GMT-03:00 1967
1500         {"America/Goose_Bay", -68670001, -3*H}, // Sun Oct 29 01:59:59 GMT-03:00 1967
1501         {"America/Goose_Bay", -68670000, -4*H}, // Sun Oct 29 01:00:00 GMT-04:00 1967
1502         {0, 0, 0}
1503     };
1504 
1505     for (int32_t i=0; DATA[i].id!=0; ++i) {
1506         const char* id = DATA[i].id;
1507         TimeZone *tz = TimeZone::createTimeZone(id);
1508         UnicodeString s;
1509         if (tz == 0) {
1510             errln("FAIL: Cannot create %s", id);
1511         } else if (tz->getID(s) != UnicodeString(id)) {
1512             errln((UnicodeString)"FAIL: createTimeZone(" + id + ") => " + s);
1513         } else {
1514             UErrorCode ec = U_ZERO_ERROR;
1515             int32_t raw, dst;
1516             UDate when = (double) DATA[i].time * U_MILLIS_PER_SECOND;
1517             tz->getOffset(when, FALSE, raw, dst, ec);
1518             if (U_FAILURE(ec)) {
1519                 errln("FAIL: getOffset");
1520             } else if ((raw+dst) != DATA[i].offset) {
1521                 errln((UnicodeString)"FAIL: " + DATA[i].id + ".getOffset(" +
1522                       //when + " = " +
1523                       dateToString(when) + ") => " +
1524                       raw + ", " + dst);
1525             } else {
1526                 logln((UnicodeString)"Ok: " + DATA[i].id + ".getOffset(" +
1527                       //when + " = " +
1528                       dateToString(when) + ") => " +
1529                       raw + ", " + dst);
1530             }
1531         }
1532         delete tz;
1533     }
1534 }
1535 
TestEquivalentIDs()1536 void TimeZoneTest::TestEquivalentIDs() {
1537     int32_t n = TimeZone::countEquivalentIDs("PST");
1538     if (n < 2) {
1539         errln((UnicodeString)"FAIL: countEquivalentIDs(PST) = " + n);
1540     } else {
1541         UBool sawLA = FALSE;
1542         for (int32_t i=0; i<n; ++i) {
1543             UnicodeString id = TimeZone::getEquivalentID("PST", i);
1544             logln((UnicodeString)"" + i + " : " + id);
1545             if (id == UnicodeString("America/Los_Angeles")) {
1546                 sawLA = TRUE;
1547             }
1548         }
1549         if (!sawLA) {
1550             errln("FAIL: America/Los_Angeles should be in the list");
1551         }
1552     }
1553 }
1554 
1555 // Test that a transition at the end of February is handled correctly.
TestFebruary()1556 void TimeZoneTest::TestFebruary() {
1557     UErrorCode status = U_ZERO_ERROR;
1558 
1559     // Time zone with daylight savings time from the first Sunday in November
1560     // to the last Sunday in February.
1561     // Similar to the new rule for Brazil (Sao Paulo) in tzdata2006n.
1562     //
1563     // Note: In tzdata2007h, the rule had changed, so no actual zones uses
1564     // lastSun in Feb anymore.
1565     SimpleTimeZone tz1(-3 * U_MILLIS_PER_HOUR,          // raw offset: 3h before (west of) GMT
1566                        UNICODE_STRING("nov-feb", 7),
1567                        UCAL_NOVEMBER, 1, UCAL_SUNDAY,   // start: November, first, Sunday
1568                        0,                               //        midnight wall time
1569                        UCAL_FEBRUARY, -1, UCAL_SUNDAY,  // end:   February, last, Sunday
1570                        0,                               //        midnight wall time
1571                        status);
1572     if (U_FAILURE(status)) {
1573         errln("Unable to create the SimpleTimeZone(nov-feb): %s", u_errorName(status));
1574         return;
1575     }
1576 
1577     // Now hardcode the same rules as for Brazil in tzdata 2006n, so that
1578     // we cover the intended code even when in the future zoneinfo hardcodes
1579     // these transition dates.
1580     SimpleTimeZone tz2(-3 * U_MILLIS_PER_HOUR,          // raw offset: 3h before (west of) GMT
1581                        UNICODE_STRING("nov-feb2", 8),
1582                        UCAL_NOVEMBER, 1, -UCAL_SUNDAY,  // start: November, 1 or after, Sunday
1583                        0,                               //        midnight wall time
1584                        UCAL_FEBRUARY, -29, -UCAL_SUNDAY,// end:   February, 29 or before, Sunday
1585                        0,                               //        midnight wall time
1586                        status);
1587     if (U_FAILURE(status)) {
1588         errln("Unable to create the SimpleTimeZone(nov-feb2): %s", u_errorName(status));
1589         return;
1590     }
1591 
1592     // Gregorian calendar with the UTC time zone for getting sample test date/times.
1593     GregorianCalendar gc(*TimeZone::getGMT(), status);
1594     if (U_FAILURE(status)) {
1595         errln("Unable to create the UTC calendar: %s", u_errorName(status));
1596         return;
1597     }
1598 
1599     struct {
1600         // UTC time.
1601         int32_t year, month, day, hour, minute, second;
1602         // Expected time zone offset in hours after GMT (negative=before GMT).
1603         int32_t offsetHours;
1604     } data[] = {
1605         { 2006, UCAL_NOVEMBER,  5, 02, 59, 59, -3 },
1606         { 2006, UCAL_NOVEMBER,  5, 03, 00, 00, -2 },
1607         { 2007, UCAL_FEBRUARY, 25, 01, 59, 59, -2 },
1608         { 2007, UCAL_FEBRUARY, 25, 02, 00, 00, -3 },
1609 
1610         { 2007, UCAL_NOVEMBER,  4, 02, 59, 59, -3 },
1611         { 2007, UCAL_NOVEMBER,  4, 03, 00, 00, -2 },
1612         { 2008, UCAL_FEBRUARY, 24, 01, 59, 59, -2 },
1613         { 2008, UCAL_FEBRUARY, 24, 02, 00, 00, -3 },
1614 
1615         { 2008, UCAL_NOVEMBER,  2, 02, 59, 59, -3 },
1616         { 2008, UCAL_NOVEMBER,  2, 03, 00, 00, -2 },
1617         { 2009, UCAL_FEBRUARY, 22, 01, 59, 59, -2 },
1618         { 2009, UCAL_FEBRUARY, 22, 02, 00, 00, -3 },
1619 
1620         { 2009, UCAL_NOVEMBER,  1, 02, 59, 59, -3 },
1621         { 2009, UCAL_NOVEMBER,  1, 03, 00, 00, -2 },
1622         { 2010, UCAL_FEBRUARY, 28, 01, 59, 59, -2 },
1623         { 2010, UCAL_FEBRUARY, 28, 02, 00, 00, -3 }
1624     };
1625 
1626     TimeZone *timezones[] = { &tz1, &tz2 };
1627 
1628     TimeZone *tz;
1629     UDate dt;
1630     int32_t t, i, raw, dst;
1631     for (t = 0; t < LENGTHOF(timezones); ++t) {
1632         tz = timezones[t];
1633         for (i = 0; i < LENGTHOF(data); ++i) {
1634             gc.set(data[i].year, data[i].month, data[i].day,
1635                    data[i].hour, data[i].minute, data[i].second);
1636             dt = gc.getTime(status);
1637             if (U_FAILURE(status)) {
1638                 errln("test case %d.%d: bad date/time %04d-%02d-%02d %02d:%02d:%02d",
1639                       t, i,
1640                       data[i].year, data[i].month + 1, data[i].day,
1641                       data[i].hour, data[i].minute, data[i].second);
1642                 status = U_ZERO_ERROR;
1643                 continue;
1644             }
1645             tz->getOffset(dt, FALSE, raw, dst, status);
1646             if (U_FAILURE(status)) {
1647                 errln("test case %d.%d: tz.getOffset(%04d-%02d-%02d %02d:%02d:%02d) fails: %s",
1648                       t, i,
1649                       data[i].year, data[i].month + 1, data[i].day,
1650                       data[i].hour, data[i].minute, data[i].second,
1651                       u_errorName(status));
1652                 status = U_ZERO_ERROR;
1653             } else if ((raw + dst) != data[i].offsetHours * U_MILLIS_PER_HOUR) {
1654                 errln("test case %d.%d: tz.getOffset(%04d-%02d-%02d %02d:%02d:%02d) returns %d+%d != %d",
1655                       t, i,
1656                       data[i].year, data[i].month + 1, data[i].day,
1657                       data[i].hour, data[i].minute, data[i].second,
1658                       raw, dst, data[i].offsetHours * U_MILLIS_PER_HOUR);
1659             }
1660         }
1661     }
1662 }
1663 
1664 #endif /* #if !UCONFIG_NO_FORMATTING */
1665