2 *******************************************************************************
3 * Copyright (C) 2007-2010, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_FORMATTING
12 #include "unicode/dtrule.h"
13 #include "unicode/tzrule.h"
14 #include "unicode/rbtz.h"
15 #include "unicode/simpletz.h"
16 #include "unicode/tzrule.h"
17 #include "unicode/calendar.h"
18 #include "unicode/gregocal.h"
19 #include "unicode/ucal.h"
20 #include "unicode/unistr.h"
21 #include "unicode/ustring.h"
22 #include "unicode/tztrans.h"
23 #include "unicode/vtzone.h"
30 #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break
31 #define HOUR (60*60*1000)
33 static const UVersionInfo ICU_453
= {4,5,3,0};
35 static const char *const TESTZIDS
[] = {
38 "America/Los_Angeles",
39 "America/Indiana/Indianapolis",
51 static UBool
hasEquivalentTransitions(/*const*/ BasicTimeZone
& tz1
, /*const*/BasicTimeZone
& tz2
,
52 UDate start
, UDate end
,
53 UBool ignoreDstAmount
, int32_t maxTransitionTimeDelta
,
56 class TestZIDEnumeration
: public StringEnumeration
{
58 TestZIDEnumeration(UBool all
= FALSE
);
59 ~TestZIDEnumeration();
61 virtual int32_t count(UErrorCode
& /*status*/) const {
64 virtual const UnicodeString
*snext(UErrorCode
& status
);
65 virtual void reset(UErrorCode
& status
);
66 static inline UClassID
getStaticClassID() {
67 return (UClassID
)&fgClassID
;
69 virtual UClassID
getDynamicClassID() const {
70 return getStaticClassID();
73 static const char fgClassID
;
76 StringEnumeration
*tzenum
;
79 const char TestZIDEnumeration::fgClassID
= 0;
81 TestZIDEnumeration::TestZIDEnumeration(UBool all
)
83 UErrorCode status
= U_ZERO_ERROR
;
85 tzenum
= TimeZone::createEnumeration();
86 len
= tzenum
->count(status
);
89 len
= (int32_t)sizeof(TESTZIDS
)/sizeof(TESTZIDS
[0]);
93 TestZIDEnumeration::~TestZIDEnumeration() {
100 TestZIDEnumeration::snext(UErrorCode
& status
) {
101 if (tzenum
!= NULL
) {
102 return tzenum
->snext(status
);
103 } else if (U_SUCCESS(status
) && idx
< len
) {
104 unistr
= UnicodeString(TESTZIDS
[idx
++], "");
111 TestZIDEnumeration::reset(UErrorCode
& status
) {
112 if (tzenum
!= NULL
) {
113 tzenum
->reset(status
);
120 void TimeZoneRuleTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
123 logln("TestSuite TestTimeZoneRule");
126 CASE(0, TestSimpleRuleBasedTimeZone
);
127 CASE(1, TestHistoricalRuleBasedTimeZone
);
128 CASE(2, TestOlsonTransition
);
129 CASE(3, TestRBTZTransition
);
130 CASE(4, TestHasEquivalentTransitions
);
131 CASE(5, TestVTimeZoneRoundTrip
);
132 CASE(6, TestVTimeZoneRoundTripPartial
);
133 CASE(7, TestVTimeZoneSimpleWrite
);
134 CASE(8, TestVTimeZoneHeaderProps
);
135 CASE(9, TestGetSimpleRules
);
136 CASE(10, TestTimeZoneRuleCoverage
);
137 CASE(11, TestSimpleTimeZoneCoverage
);
138 CASE(12, TestVTimeZoneCoverage
);
139 CASE(13, TestVTimeZoneParse
);
142 CASE(16, TestVTimeZoneWrapper
);
143 default: name
= ""; break;
148 * Compare SimpleTimeZone with equivalent RBTZ
151 TimeZoneRuleTest::TestSimpleRuleBasedTimeZone(void) {
152 UErrorCode status
= U_ZERO_ERROR
;
153 SimpleTimeZone
stz(-1*HOUR
, "TestSTZ",
154 UCAL_SEPTEMBER
, -30, -UCAL_SATURDAY
, 1*HOUR
, SimpleTimeZone::WALL_TIME
,
155 UCAL_FEBRUARY
, 2, UCAL_SUNDAY
, 1*HOUR
, SimpleTimeZone::WALL_TIME
,
157 if (U_FAILURE(status
)) {
158 errln("FAIL: Couldn't create SimpleTimezone.");
162 AnnualTimeZoneRule
*atzr
;
163 int32_t STARTYEAR
= 2000;
165 InitialTimeZoneRule
*ir
= new InitialTimeZoneRule(
166 "RBTZ_Initial", // Initial time Name
167 -1*HOUR
, // Raw offset
168 1*HOUR
); // DST saving amount
171 RuleBasedTimeZone
*rbtz1
= new RuleBasedTimeZone("RBTZ1", ir
->clone());
172 dtr
= new DateTimeRule(UCAL_SEPTEMBER
, 30, UCAL_SATURDAY
, FALSE
,
173 1*HOUR
, DateTimeRule::WALL_TIME
); // SUN<=30 in September, at 1AM wall time
174 atzr
= new AnnualTimeZoneRule("RBTZ_DST1",
175 -1*HOUR
/*rawOffset*/, 1*HOUR
/*dstSavings*/, dtr
,
176 STARTYEAR
, AnnualTimeZoneRule::MAX_YEAR
);
177 rbtz1
->addTransitionRule(atzr
, status
);
178 if (U_FAILURE(status
)) {
179 errln("FAIL: couldn't add AnnualTimeZoneRule 1-1.");
181 dtr
= new DateTimeRule(UCAL_FEBRUARY
, 2, UCAL_SUNDAY
,
182 1*HOUR
, DateTimeRule::WALL_TIME
); // 2nd Sunday in February, at 1AM wall time
183 atzr
= new AnnualTimeZoneRule("RBTZ_STD1",
184 -1*HOUR
/*rawOffset*/, 0 /*dstSavings*/, dtr
,
185 STARTYEAR
, AnnualTimeZoneRule::MAX_YEAR
);
186 rbtz1
->addTransitionRule(atzr
, status
);
187 if (U_FAILURE(status
)) {
188 errln("FAIL: couldn't add AnnualTimeZoneRule 1-2.");
190 rbtz1
->complete(status
);
191 if (U_FAILURE(status
)) {
192 errln("FAIL: couldn't complete RBTZ 1.");
195 // Equivalent, but different date rule type
196 RuleBasedTimeZone
*rbtz2
= new RuleBasedTimeZone("RBTZ2", ir
->clone());
197 dtr
= new DateTimeRule(UCAL_SEPTEMBER
, -1, UCAL_SATURDAY
,
198 1*HOUR
, DateTimeRule::WALL_TIME
); // Last Sunday in September at 1AM wall time
199 atzr
= new AnnualTimeZoneRule("RBTZ_DST2", -1*HOUR
, 1*HOUR
, dtr
, STARTYEAR
, AnnualTimeZoneRule::MAX_YEAR
);
200 rbtz2
->addTransitionRule(atzr
, status
);
201 if (U_FAILURE(status
)) {
202 errln("FAIL: couldn't add AnnualTimeZoneRule 2-1.");
204 dtr
= new DateTimeRule(UCAL_FEBRUARY
, 8, UCAL_SUNDAY
, true,
205 1*HOUR
, DateTimeRule::WALL_TIME
); // SUN>=8 in February, at 1AM wall time
206 atzr
= new AnnualTimeZoneRule("RBTZ_STD2", -1*HOUR
, 0, dtr
, STARTYEAR
, AnnualTimeZoneRule::MAX_YEAR
);
207 rbtz2
->addTransitionRule(atzr
, status
);
208 if (U_FAILURE(status
)) {
209 errln("FAIL: couldn't add AnnualTimeZoneRule 2-2.");
211 rbtz2
->complete(status
);
212 if (U_FAILURE(status
)) {
213 errln("FAIL: couldn't complete RBTZ 2");
216 // Equivalent, but different time rule type
217 RuleBasedTimeZone
*rbtz3
= new RuleBasedTimeZone("RBTZ3", ir
->clone());
218 dtr
= new DateTimeRule(UCAL_SEPTEMBER
, 30, UCAL_SATURDAY
, false,
219 2*HOUR
, DateTimeRule::UTC_TIME
);
220 atzr
= new AnnualTimeZoneRule("RBTZ_DST3", -1*HOUR
, 1*HOUR
, dtr
, STARTYEAR
, AnnualTimeZoneRule::MAX_YEAR
);
221 rbtz3
->addTransitionRule(atzr
, status
);
222 if (U_FAILURE(status
)) {
223 errln("FAIL: couldn't add AnnualTimeZoneRule 3-1.");
225 dtr
= new DateTimeRule(UCAL_FEBRUARY
, 2, UCAL_SUNDAY
,
226 0*HOUR
, DateTimeRule::STANDARD_TIME
);
227 atzr
= new AnnualTimeZoneRule("RBTZ_STD3", -1*HOUR
, 0, dtr
, STARTYEAR
, AnnualTimeZoneRule::MAX_YEAR
);
228 rbtz3
->addTransitionRule(atzr
, status
);
229 if (U_FAILURE(status
)) {
230 errln("FAIL: couldn't add AnnualTimeZoneRule 3-2.");
232 rbtz3
->complete(status
);
233 if (U_FAILURE(status
)) {
234 errln("FAIL: couldn't complete RBTZ 3");
237 // Check equivalency for 10 years
238 UDate start
= getUTCMillis(STARTYEAR
, UCAL_JANUARY
, 1);
239 UDate until
= getUTCMillis(STARTYEAR
+ 10, UCAL_JANUARY
, 1);
241 if (!(stz
.hasEquivalentTransitions(*rbtz1
, start
, until
, TRUE
, status
))) {
242 errln("FAIL: rbtz1 must be equivalent to the SimpleTimeZone in the time range.");
244 if (U_FAILURE(status
)) {
245 errln("FAIL: error returned from hasEquivalentTransitions");
247 if (!(stz
.hasEquivalentTransitions(*rbtz2
, start
, until
, TRUE
, status
))) {
248 errln("FAIL: rbtz2 must be equivalent to the SimpleTimeZone in the time range.");
250 if (U_FAILURE(status
)) {
251 errln("FAIL: error returned from hasEquivalentTransitions");
253 if (!(stz
.hasEquivalentTransitions(*rbtz3
, start
, until
, TRUE
, status
))) {
254 errln("FAIL: rbtz3 must be equivalent to the SimpleTimeZone in the time range.");
256 if (U_FAILURE(status
)) {
257 errln("FAIL: error returned from hasEquivalentTransitions");
261 if (rbtz1
->hasSameRules(*rbtz2
)) {
262 errln("FAIL: rbtz1 and rbtz2 have different rules, but returned true.");
264 if (rbtz1
->hasSameRules(*rbtz3
)) {
265 errln("FAIL: rbtz1 and rbtz3 have different rules, but returned true.");
267 RuleBasedTimeZone
*rbtz1c
= (RuleBasedTimeZone
*)rbtz1
->clone();
268 if (!rbtz1
->hasSameRules(*rbtz1c
)) {
269 errln("FAIL: Cloned RuleBasedTimeZone must have the same rules with the original.");
273 int32_t era
, year
, month
, dayOfMonth
, dayOfWeek
, millisInDay
;
275 int32_t offset
, dstSavings
;
278 GregorianCalendar
*cal
= new GregorianCalendar(status
);
279 if (U_FAILURE(status
)) {
280 dataerrln("FAIL: Could not create a Gregorian calendar instance.: %s", u_errorName(status
));
287 cal
->setTimeZone(*rbtz1
);
291 cal
->set(UCAL_ERA
, GregorianCalendar::BC
);
292 cal
->set(1000, UCAL_JANUARY
, 1);
294 era
= cal
->get(UCAL_ERA
, status
);
295 year
= cal
->get(UCAL_YEAR
, status
);
296 month
= cal
->get(UCAL_MONTH
, status
);
297 dayOfMonth
= cal
->get(UCAL_DAY_OF_MONTH
, status
);
298 dayOfWeek
= cal
->get(UCAL_DAY_OF_WEEK
, status
);
299 millisInDay
= cal
->get(UCAL_MILLISECONDS_IN_DAY
, status
);
300 time
= cal
->getTime(status
);
301 if (U_FAILURE(status
)) {
302 errln("FAIL: Could not get calendar field values.");
304 offset
= rbtz1
->getOffset(era
, year
, month
, dayOfMonth
, dayOfWeek
, millisInDay
, status
);
305 if (U_FAILURE(status
)) {
306 errln("FAIL: getOffset(7 args) failed.");
309 errln(UnicodeString("FAIL: Invalid time zone offset: ") + offset
+ " /expected: 0");
311 dst
= rbtz1
->inDaylightTime(time
, status
);
312 if (U_FAILURE(status
)) {
313 errln("FAIL: inDaylightTime failed.");
316 errln("FAIL: Invalid daylight saving time");
318 rbtz1
->getOffset(time
, TRUE
, offset
, dstSavings
, status
);
319 if (U_FAILURE(status
)) {
320 errln("FAIL: getOffset(5 args) failed.");
322 if (offset
!= -3600000) {
323 errln(UnicodeString("FAIL: Invalid time zone raw offset: ") + offset
+ " /expected: -3600000");
325 if (dstSavings
!= 3600000) {
326 errln(UnicodeString("FAIL: Invalid DST amount: ") + dstSavings
+ " /expected: 3600000");
330 cal
->set(UCAL_ERA
, GregorianCalendar::AD
);
331 cal
->set(2000, UCAL_JULY
, 1);
333 era
= cal
->get(UCAL_ERA
, status
);
334 year
= cal
->get(UCAL_YEAR
, status
);
335 month
= cal
->get(UCAL_MONTH
, status
);
336 dayOfMonth
= cal
->get(UCAL_DAY_OF_MONTH
, status
);
337 dayOfWeek
= cal
->get(UCAL_DAY_OF_WEEK
, status
);
338 millisInDay
= cal
->get(UCAL_MILLISECONDS_IN_DAY
, status
);
339 time
= cal
->getTime(status
);
340 if (U_FAILURE(status
)) {
341 errln("FAIL: Could not get calendar field values.");
343 offset
= rbtz1
->getOffset(era
, year
, month
, dayOfMonth
, dayOfWeek
, millisInDay
, status
);
344 if (U_FAILURE(status
)) {
345 errln("FAIL: getOffset(7 args) failed.");
347 if (offset
!= -3600000) {
348 errln((UnicodeString
)"FAIL: Invalid time zone offset: " + offset
+ " /expected: -3600000");
350 dst
= rbtz1
->inDaylightTime(time
, status
);
351 if (U_FAILURE(status
)) {
352 errln("FAIL: inDaylightTime failed.");
355 errln("FAIL: Invalid daylight saving time");
357 rbtz1
->getOffset(time
, TRUE
, offset
, dstSavings
, status
);
358 if (U_FAILURE(status
)) {
359 errln("FAIL: getOffset(5 args) failed.");
361 if (offset
!= -3600000) {
362 errln((UnicodeString
)"FAIL: Invalid time zone raw offset: " + offset
+ " /expected: -3600000");
364 if (dstSavings
!= 0) {
365 errln((UnicodeString
)"FAIL: Invalid DST amount: " + dstSavings
+ " /expected: 0");
369 offset
= rbtz1
->getRawOffset();
370 if (offset
!= -1*HOUR
) {
371 errln((UnicodeString
)"FAIL: Invalid time zone raw offset returned by getRawOffset: "
372 + offset
+ " /expected: -3600000");
376 RuleBasedTimeZone
rbtz0("RBTZ1", ir
->clone());
377 if (rbtz0
== *rbtz1
|| !(rbtz0
!= *rbtz1
)) {
378 errln("FAIL: RuleBasedTimeZone rbtz0 is not equal to rbtz1, but got wrong result");
381 if (rbtz0
!= *rbtz1
|| !(rbtz0
== *rbtz1
)) {
382 errln("FAIL: RuleBasedTimeZone rbtz0 is equal to rbtz1, but got wrong result");
386 const int32_t RAW
= -10*HOUR
;
387 rbtz0
.setRawOffset(RAW
);
388 if (rbtz0
.getRawOffset() != RAW
) {
389 logln("setRawOffset is implemented in RuleBasedTimeZone");
393 if (!rbtz1
->useDaylightTime()) {
394 errln("FAIL: useDaylightTime returned FALSE");
397 // Try to add 3rd final rule
398 dtr
= new DateTimeRule(UCAL_OCTOBER
, 15, 1*HOUR
, DateTimeRule::WALL_TIME
);
399 atzr
= new AnnualTimeZoneRule("3RD_ATZ", -1*HOUR
, 2*HOUR
, dtr
, STARTYEAR
, AnnualTimeZoneRule::MAX_YEAR
);
400 rbtz1
->addTransitionRule(atzr
, status
);
401 if (U_SUCCESS(status
)) {
402 errln("FAIL: 3rd final rule must be rejected");
407 // Try to add an initial rule
408 InitialTimeZoneRule
*ir1
= new InitialTimeZoneRule("Test Initial", 2*HOUR
, 0);
409 rbtz1
->addTransitionRule(ir1
, status
);
410 if (U_SUCCESS(status
)) {
411 errln("FAIL: InitialTimeZoneRule must be rejected");
425 * Test equivalency between OlsonTimeZone and custom RBTZ representing the
426 * equivalent rules in a certain time range
429 TimeZoneRuleTest::TestHistoricalRuleBasedTimeZone(void) {
430 UErrorCode status
= U_ZERO_ERROR
;
432 // Compare to America/New_York with equivalent RBTZ
433 BasicTimeZone
*ny
= (BasicTimeZone
*)TimeZone::createTimeZone("America/New_York");
436 InitialTimeZoneRule
*ir
= new InitialTimeZoneRule("EST", -5*HOUR
, 0);
437 RuleBasedTimeZone
*rbtz
= new RuleBasedTimeZone("EST5EDT", ir
);
440 AnnualTimeZoneRule
*tzr
;
443 dtr
= new DateTimeRule(UCAL_OCTOBER
, -1, UCAL_SUNDAY
,
444 2*HOUR
, DateTimeRule::WALL_TIME
); // Last Sunday in October, at 2AM wall time
445 tzr
= new AnnualTimeZoneRule("EST", -5*HOUR
/*rawOffset*/, 0 /*dstSavings*/, dtr
, 1967, 2006);
446 rbtz
->addTransitionRule(tzr
, status
);
447 if (U_FAILURE(status
)) {
448 errln("FAIL: couldn't add AnnualTimeZoneRule 1.");
451 dtr
= new DateTimeRule(UCAL_NOVEMBER
, 1, UCAL_SUNDAY
,
452 true, 2*HOUR
, DateTimeRule::WALL_TIME
); // SUN>=1 in November, at 2AM wall time
453 tzr
= new AnnualTimeZoneRule("EST", -5*HOUR
, 0, dtr
, 2007, AnnualTimeZoneRule::MAX_YEAR
);
454 rbtz
->addTransitionRule(tzr
, status
);
455 if (U_FAILURE(status
)) {
456 errln("FAIL: couldn't add AnnualTimeZoneRule 2.");
459 // Daylight saving time
460 dtr
= new DateTimeRule(UCAL_APRIL
, -1, UCAL_SUNDAY
,
461 2*HOUR
, DateTimeRule::WALL_TIME
); // Last Sunday in April, at 2AM wall time
462 tzr
= new AnnualTimeZoneRule("EDT", -5*HOUR
, 1*HOUR
, dtr
, 1967, 1973);
463 rbtz
->addTransitionRule(tzr
, status
);
464 if (U_FAILURE(status
)) {
465 errln("FAIL: couldn't add AnnualTimeZoneRule 3.");
468 dtr
= new DateTimeRule(UCAL_JANUARY
, 6,
469 2*HOUR
, DateTimeRule::WALL_TIME
); // January 6, at 2AM wall time
470 tzr
= new AnnualTimeZoneRule("EDT", -5*HOUR
, 1*HOUR
, dtr
, 1974, 1974);
471 rbtz
->addTransitionRule(tzr
, status
);
472 if (U_FAILURE(status
)) {
473 errln("FAIL: couldn't add AnnualTimeZoneRule 4.");
476 dtr
= new DateTimeRule(UCAL_FEBRUARY
, 23,
477 2*HOUR
, DateTimeRule::WALL_TIME
); // February 23, at 2AM wall time
478 tzr
= new AnnualTimeZoneRule("EDT", -5*HOUR
, 1*HOUR
, dtr
, 1975, 1975);
479 rbtz
->addTransitionRule(tzr
, status
);
480 if (U_FAILURE(status
)) {
481 errln("FAIL: couldn't add AnnualTimeZoneRule 5.");
484 dtr
= new DateTimeRule(UCAL_APRIL
, -1, UCAL_SUNDAY
,
485 2*HOUR
, DateTimeRule::WALL_TIME
); // Last Sunday in April, at 2AM wall time
486 tzr
= new AnnualTimeZoneRule("EDT", -5*HOUR
, 1*HOUR
, dtr
, 1976, 1986);
487 rbtz
->addTransitionRule(tzr
, status
);
488 if (U_FAILURE(status
)) {
489 errln("FAIL: couldn't add AnnualTimeZoneRule 6.");
492 dtr
= new DateTimeRule(UCAL_APRIL
, 1, UCAL_SUNDAY
,
493 true, 2*HOUR
, DateTimeRule::WALL_TIME
); // SUN>=1 in April, at 2AM wall time
494 tzr
= new AnnualTimeZoneRule("EDT", -5*HOUR
, 1*HOUR
, dtr
, 1987, 2006);
495 rbtz
->addTransitionRule(tzr
, status
);
496 if (U_FAILURE(status
)) {
497 errln("FAIL: couldn't add AnnualTimeZoneRule 7.");
500 dtr
= new DateTimeRule(UCAL_MARCH
, 8, UCAL_SUNDAY
,
501 true, 2*HOUR
, DateTimeRule::WALL_TIME
); // SUN>=8 in March, at 2AM wall time
502 tzr
= new AnnualTimeZoneRule("EDT", -5*HOUR
, 1*HOUR
, dtr
, 2007, AnnualTimeZoneRule::MAX_YEAR
);
503 rbtz
->addTransitionRule(tzr
, status
);
504 if (U_FAILURE(status
)) {
505 errln("FAIL: couldn't add AnnualTimeZoneRule 7.");
508 rbtz
->complete(status
);
509 if (U_FAILURE(status
)) {
510 errln("FAIL: couldn't complete RBTZ.");
513 // hasEquivalentTransitions
514 UDate jan1_1950
= getUTCMillis(1950, UCAL_JANUARY
, 1);
515 UDate jan1_1967
= getUTCMillis(1971, UCAL_JANUARY
, 1);
516 UDate jan1_2010
= getUTCMillis(2010, UCAL_JANUARY
, 1);
518 if (!ny
->hasEquivalentTransitions(*rbtz
, jan1_1967
, jan1_2010
, TRUE
, status
)) {
519 dataerrln("FAIL: The RBTZ must be equivalent to America/New_York between 1967 and 2010");
521 if (U_FAILURE(status
)) {
522 errln("FAIL: error returned from hasEquivalentTransitions for ny/rbtz 1967-2010");
524 if (ny
->hasEquivalentTransitions(*rbtz
, jan1_1950
, jan1_2010
, TRUE
, status
)) {
525 errln("FAIL: The RBTZ must not be equivalent to America/New_York between 1950 and 2010");
527 if (U_FAILURE(status
)) {
528 errln("FAIL: error returned from hasEquivalentTransitions for ny/rbtz 1950-2010");
531 // Same with above, but calling RBTZ#hasEquivalentTransitions against OlsonTimeZone
532 if (!rbtz
->hasEquivalentTransitions(*ny
, jan1_1967
, jan1_2010
, TRUE
, status
)) {
533 dataerrln("FAIL: The RBTZ must be equivalent to America/New_York between 1967 and 2010 ");
535 if (U_FAILURE(status
)) {
536 errln("FAIL: error returned from hasEquivalentTransitions for rbtz/ny 1967-2010");
538 if (rbtz
->hasEquivalentTransitions(*ny
, jan1_1950
, jan1_2010
, TRUE
, status
)) {
539 errln("FAIL: The RBTZ must not be equivalent to America/New_York between 1950 and 2010");
541 if (U_FAILURE(status
)) {
542 errln("FAIL: error returned from hasEquivalentTransitions for rbtz/ny 1950-2010");
546 if (ny
->hasSameRules(*rbtz
) || rbtz
->hasSameRules(*ny
)) {
547 errln("FAIL: hasSameRules must return false");
549 RuleBasedTimeZone
*rbtzc
= (RuleBasedTimeZone
*)rbtz
->clone();
550 if (!rbtz
->hasSameRules(*rbtzc
) || !rbtz
->hasEquivalentTransitions(*rbtzc
, jan1_1950
, jan1_2010
, TRUE
, status
)) {
551 errln("FAIL: hasSameRules/hasEquivalentTransitions must return true for cloned RBTZs");
553 if (U_FAILURE(status
)) {
554 errln("FAIL: error returned from hasEquivalentTransitions for rbtz/rbtzc 1950-2010");
558 getUTCMillis(2006, UCAL_MARCH
, 15),
559 getUTCMillis(2006, UCAL_NOVEMBER
, 1),
560 getUTCMillis(2007, UCAL_MARCH
, 15),
561 getUTCMillis(2007, UCAL_NOVEMBER
, 1),
562 getUTCMillis(2008, UCAL_MARCH
, 15),
563 getUTCMillis(2008, UCAL_NOVEMBER
, 1),
566 int32_t offset1
, dst1
;
567 int32_t offset2
, dst2
;
569 for (int i
= 0; times
[i
] != 0; i
++) {
570 // Check getOffset - must return the same results for these time data
571 rbtz
->getOffset(times
[i
], FALSE
, offset1
, dst1
, status
);
572 if (U_FAILURE(status
)) {
573 errln("FAIL: rbtz->getOffset failed");
575 ny
->getOffset(times
[i
], FALSE
, offset2
, dst2
, status
);
576 if (U_FAILURE(status
)) {
577 errln("FAIL: ny->getOffset failed");
579 if (offset1
!= offset2
|| dst1
!= dst2
) {
580 dataerrln("FAIL: Incompatible time zone offset/dstSavings for ny and rbtz");
583 // Check inDaylightTime
584 if (rbtz
->inDaylightTime(times
[i
], status
) != ny
->inDaylightTime(times
[i
], status
)) {
585 dataerrln("FAIL: Incompatible daylight saving time for ny and rbtz");
587 if (U_FAILURE(status
)) {
588 errln("FAIL: inDaylightTime failed");
598 * Check if transitions returned by getNextTransition/getPreviousTransition
599 * are actual time transitions.
602 TimeZoneRuleTest::TestOlsonTransition(void) {
604 const int32_t TESTYEARS
[][2] = {
605 {1895, 1905}, // including int32 minimum second
606 {1965, 1975}, // including the epoch
607 {1995, 2015}, // practical year range
611 UErrorCode status
= U_ZERO_ERROR
;
612 TestZIDEnumeration
tzenum(!quick
);
614 const UnicodeString
*tzid
= tzenum
.snext(status
);
618 if (U_FAILURE(status
)) {
619 errln("FAIL: error returned while enumerating timezone IDs.");
622 BasicTimeZone
*tz
= (BasicTimeZone
*)TimeZone::createTimeZone(*tzid
);
623 for (int32_t i
= 0; TESTYEARS
[i
][0] != 0 || TESTYEARS
[i
][1] != 0; i
++) {
624 UDate lo
= getUTCMillis(TESTYEARS
[i
][0], UCAL_JANUARY
, 1);
625 UDate hi
= getUTCMillis(TESTYEARS
[i
][1], UCAL_JANUARY
, 1);
626 verifyTransitions(*tz
, lo
, hi
);
633 * Check if an OlsonTimeZone and its equivalent RBTZ have the exact same
637 TimeZoneRuleTest::TestRBTZTransition(void) {
638 const int32_t STARTYEARS
[] = {
646 UErrorCode status
= U_ZERO_ERROR
;
647 TestZIDEnumeration
tzenum(!quick
);
649 const UnicodeString
*tzid
= tzenum
.snext(status
);
653 if (U_FAILURE(status
)) {
654 errln("FAIL: error returned while enumerating timezone IDs.");
657 BasicTimeZone
*tz
= (BasicTimeZone
*)TimeZone::createTimeZone(*tzid
);
658 int32_t ruleCount
= tz
->countTransitionRules(status
);
660 const InitialTimeZoneRule
*initial
;
661 const TimeZoneRule
**trsrules
= new const TimeZoneRule
*[ruleCount
];
662 tz
->getTimeZoneRules(initial
, trsrules
, ruleCount
, status
);
663 if (U_FAILURE(status
)) {
664 errln((UnicodeString
)"FAIL: failed to get the TimeZoneRules from time zone " + *tzid
);
666 RuleBasedTimeZone
*rbtz
= new RuleBasedTimeZone(*tzid
, initial
->clone());
667 if (U_FAILURE(status
)) {
668 errln((UnicodeString
)"FAIL: failed to get the transition rule count from time zone " + *tzid
);
670 for (int32_t i
= 0; i
< ruleCount
; i
++) {
671 rbtz
->addTransitionRule(trsrules
[i
]->clone(), status
);
672 if (U_FAILURE(status
)) {
673 errln((UnicodeString
)"FAIL: failed to add a transition rule at index " + i
+ " to the RBTZ for " + *tzid
);
676 rbtz
->complete(status
);
677 if (U_FAILURE(status
)) {
678 errln((UnicodeString
)"FAIL: complete() failed for the RBTZ for " + *tzid
);
681 for (int32_t idx
= 0; STARTYEARS
[idx
] != 0; idx
++) {
682 UDate start
= getUTCMillis(STARTYEARS
[idx
], UCAL_JANUARY
, 1);
683 UDate until
= getUTCMillis(STARTYEARS
[idx
] + 20, UCAL_JANUARY
, 1);
684 // Compare the original OlsonTimeZone with the RBTZ starting the startTime for 20 years
687 compareTransitionsAscending(*tz
, *rbtz
, start
, until
, FALSE
);
688 // Ascending/inclusive
689 compareTransitionsAscending(*tz
, *rbtz
, start
+ 1, until
, TRUE
);
691 compareTransitionsDescending(*tz
, *rbtz
, start
, until
, FALSE
);
692 // Descending/inclusive
693 compareTransitionsDescending(*tz
, *rbtz
, start
+ 1, until
, TRUE
);
702 TimeZoneRuleTest::TestHasEquivalentTransitions(void) {
703 // America/New_York and America/Indiana/Indianapolis are equivalent
705 UErrorCode status
= U_ZERO_ERROR
;
706 BasicTimeZone
*newyork
= (BasicTimeZone
*)TimeZone::createTimeZone("America/New_York");
707 BasicTimeZone
*indianapolis
= (BasicTimeZone
*)TimeZone::createTimeZone("America/Indiana/Indianapolis");
708 BasicTimeZone
*gmt_5
= (BasicTimeZone
*)TimeZone::createTimeZone("Etc/GMT+5");
710 UDate jan1_1971
= getUTCMillis(1971, UCAL_JANUARY
, 1);
711 UDate jan1_2005
= getUTCMillis(2005, UCAL_JANUARY
, 1);
712 UDate jan1_2006
= getUTCMillis(2006, UCAL_JANUARY
, 1);
713 UDate jan1_2007
= getUTCMillis(2007, UCAL_JANUARY
, 1);
714 UDate jan1_2011
= getUTCMillis(2010, UCAL_JANUARY
, 1);
716 if (newyork
->hasEquivalentTransitions(*indianapolis
, jan1_2005
, jan1_2011
, TRUE
, status
)) {
717 dataerrln("FAIL: New_York is not equivalent to Indianapolis between 2005 and 2010");
719 if (U_FAILURE(status
)) {
720 errln("FAIL: error status is returned from hasEquivalentTransition");
722 if (!newyork
->hasEquivalentTransitions(*indianapolis
, jan1_2006
, jan1_2011
, TRUE
, status
)) {
723 errln("FAIL: New_York is equivalent to Indianapolis between 2006 and 2010");
725 if (U_FAILURE(status
)) {
726 errln("FAIL: error status is returned from hasEquivalentTransition");
729 if (!indianapolis
->hasEquivalentTransitions(*gmt_5
, jan1_1971
, jan1_2006
, TRUE
, status
)) {
730 errln("FAIL: Indianapolis is equivalent to GMT+5 between 1971 and 2005");
732 if (U_FAILURE(status
)) {
733 errln("FAIL: error status is returned from hasEquivalentTransition");
735 if (indianapolis
->hasEquivalentTransitions(*gmt_5
, jan1_1971
, jan1_2007
, TRUE
, status
)) {
736 dataerrln("FAIL: Indianapolis is not equivalent to GMT+5 between 1971 and 2006");
738 if (U_FAILURE(status
)) {
739 errln("FAIL: error status is returned from hasEquivalentTransition");
743 BasicTimeZone
*newyork2
= (BasicTimeZone
*)newyork
->clone();
744 if (!newyork
->hasEquivalentTransitions(*newyork2
, jan1_1971
, jan1_2011
, FALSE
, status
)) {
745 errln("FAIL: Cloned TimeZone must have the same transitions");
747 if (U_FAILURE(status
)) {
748 errln("FAIL: error status is returned from hasEquivalentTransition for newyork/newyork2");
750 if (!newyork
->hasEquivalentTransitions(*newyork2
, jan1_1971
, jan1_2011
, TRUE
, status
)) {
751 errln("FAIL: Cloned TimeZone must have the same transitions");
753 if (U_FAILURE(status
)) {
754 errln("FAIL: error status is returned from hasEquivalentTransition for newyork/newyork2");
757 // America/New_York and America/Los_Angeles has same DST start rules, but
758 // raw offsets are different
759 BasicTimeZone
*losangeles
= (BasicTimeZone
*)TimeZone::createTimeZone("America/Los_Angeles");
760 if (newyork
->hasEquivalentTransitions(*losangeles
, jan1_2006
, jan1_2011
, TRUE
, status
)) {
761 dataerrln("FAIL: New_York is not equivalent to Los Angeles, but returned true");
763 if (U_FAILURE(status
)) {
764 errln("FAIL: error status is returned from hasEquivalentTransition for newyork/losangeles");
775 * Write out time zone rules of OlsonTimeZone into VTIMEZONE format, create a new
776 * VTimeZone from the VTIMEZONE data, then compare transitions
779 TimeZoneRuleTest::TestVTimeZoneRoundTrip(void) {
780 UDate startTime
= getUTCMillis(1850, UCAL_JANUARY
, 1);
781 UDate endTime
= getUTCMillis(2050, UCAL_JANUARY
, 1);
783 UErrorCode status
= U_ZERO_ERROR
;
784 TestZIDEnumeration
tzenum(!quick
);
786 const UnicodeString
*tzid
= tzenum
.snext(status
);
790 if (U_FAILURE(status
)) {
791 errln("FAIL: error returned while enumerating timezone IDs.");
794 BasicTimeZone
*tz
= (BasicTimeZone
*)TimeZone::createTimeZone(*tzid
);
795 VTimeZone
*vtz_org
= VTimeZone::createVTimeZoneByID(*tzid
);
796 vtz_org
->setTZURL("http://source.icu-project.org/timezone");
797 vtz_org
->setLastModified(Calendar::getNow());
798 VTimeZone
*vtz_new
= NULL
;
799 UnicodeString vtzdata
;
800 // Write out VTIMEZONE data
801 vtz_org
->write(vtzdata
, status
);
802 if (U_FAILURE(status
)) {
803 errln((UnicodeString
)"FAIL: error returned while writing time zone rules for " +
804 *tzid
+ " into VTIMEZONE format.");
806 // Read VTIMEZONE data
807 vtz_new
= VTimeZone::createVTimeZone(vtzdata
, status
);
808 if (U_FAILURE(status
)) {
809 errln((UnicodeString
)"FAIL: error returned while reading VTIMEZONE data for " + *tzid
);
811 // Write out VTIMEZONE one more time
812 UnicodeString vtzdata1
;
813 vtz_new
->write(vtzdata1
, status
);
814 if (U_FAILURE(status
)) {
815 errln((UnicodeString
)"FAIL: error returned while writing time zone rules for " +
816 *tzid
+ "(vtz_new) into VTIMEZONE format.");
818 // Make sure VTIMEZONE data is exactly same with the first one
819 if (vtzdata
!= vtzdata1
) {
820 errln((UnicodeString
)"FAIL: different VTIMEZONE data after round trip for " + *tzid
);
823 // Check equivalency after the first transition.
824 // The DST information before the first transition might be lost
825 // because there is no good way to represent the initial time with
827 int32_t raw1
, raw2
, dst1
, dst2
;
828 tz
->getOffset(startTime
, FALSE
, raw1
, dst1
, status
);
829 vtz_new
->getOffset(startTime
, FALSE
, raw2
, dst2
, status
);
830 if (U_FAILURE(status
)) {
831 errln("FAIL: error status is returned from getOffset");
833 if (raw1
+ dst1
!= raw2
+ dst2
) {
834 errln("FAIL: VTimeZone for " + *tzid
+
835 " is not equivalent to its OlsonTimeZone corresponding at "
836 + dateToString(startTime
));
838 TimeZoneTransition trans
;
839 UBool avail
= tz
->getNextTransition(startTime
, FALSE
, trans
);
841 if (!vtz_new
->hasEquivalentTransitions(*tz
, trans
.getTime(),
842 endTime
, TRUE
, status
)) {
843 int32_t maxDelta
= 1000;
844 if (!hasEquivalentTransitions(*vtz_new
, *tz
, trans
.getTime() + maxDelta
,
845 endTime
, TRUE
, maxDelta
, status
)) {
846 errln("FAIL: VTimeZone for " + *tzid
+
847 " is not equivalent to its OlsonTimeZone corresponding.");
849 logln("VTimeZone for " + *tzid
+
850 " differs from its OlsonTimeZone corresponding with maximum transition time delta - " + maxDelta
);
853 if (U_FAILURE(status
)) {
854 errln("FAIL: error status is returned from hasEquivalentTransition");
859 if (vtz_new
!= NULL
) {
870 * Write out time zone rules of OlsonTimeZone after a cutover date into VTIMEZONE format,
871 * create a new VTimeZone from the VTIMEZONE data, then compare transitions
874 TimeZoneRuleTest::TestVTimeZoneRoundTripPartial(void) {
875 const int32_t STARTYEARS
[] = {
881 UDate endTime
= getUTCMillis(2050, UCAL_JANUARY
, 1);
883 UErrorCode status
= U_ZERO_ERROR
;
884 TestZIDEnumeration
tzenum(!quick
);
886 const UnicodeString
*tzid
= tzenum
.snext(status
);
890 if (U_FAILURE(status
)) {
891 errln("FAIL: error returned while enumerating timezone IDs.");
894 BasicTimeZone
*tz
= (BasicTimeZone
*)TimeZone::createTimeZone(*tzid
);
895 VTimeZone
*vtz_org
= VTimeZone::createVTimeZoneByID(*tzid
);
896 VTimeZone
*vtz_new
= NULL
;
897 UnicodeString vtzdata
;
899 for (int32_t i
= 0; STARTYEARS
[i
] != 0; i
++) {
900 // Write out VTIMEZONE
901 UDate startTime
= getUTCMillis(STARTYEARS
[i
], UCAL_JANUARY
, 1);
902 vtz_org
->write(startTime
, vtzdata
, status
);
903 if (U_FAILURE(status
)) {
904 errln((UnicodeString
)"FAIL: error returned while writing time zone rules for " +
905 *tzid
+ " into VTIMEZONE format since " + dateToString(startTime
));
907 // Read VTIMEZONE data
908 vtz_new
= VTimeZone::createVTimeZone(vtzdata
, status
);
909 if (U_FAILURE(status
)) {
910 errln((UnicodeString
)"FAIL: error returned while reading VTIMEZONE data for " + *tzid
911 + " since " + dateToString(startTime
));
913 // Check equivalency after the first transition.
914 // The DST information before the first transition might be lost
915 // because there is no good way to represent the initial time with
917 int32_t raw1
, raw2
, dst1
, dst2
;
918 tz
->getOffset(startTime
, FALSE
, raw1
, dst1
, status
);
919 vtz_new
->getOffset(startTime
, FALSE
, raw2
, dst2
, status
);
920 if (U_FAILURE(status
)) {
921 errln("FAIL: error status is returned from getOffset");
923 if (raw1
+ dst1
!= raw2
+ dst2
) {
924 errln("FAIL: VTimeZone for " + *tzid
+
925 " is not equivalent to its OlsonTimeZone corresponding at "
926 + dateToString(startTime
));
928 TimeZoneTransition trans
;
929 UBool avail
= tz
->getNextTransition(startTime
, FALSE
, trans
);
931 if (!vtz_new
->hasEquivalentTransitions(*tz
, trans
.getTime(),
932 endTime
, TRUE
, status
)) {
933 int32_t maxDelta
= 1000;
934 if (!hasEquivalentTransitions(*vtz_new
, *tz
, trans
.getTime() + maxDelta
,
935 endTime
, TRUE
, maxDelta
, status
)) {
936 errln("FAIL: VTimeZone for " + *tzid
+
937 " is not equivalent to its OlsonTimeZone corresponding.");
939 logln("VTimeZone for " + *tzid
+
940 " differs from its OlsonTimeZone corresponding with maximum transition time delta - " + maxDelta
);
944 if (U_FAILURE(status
)) {
945 errln("FAIL: error status is returned from hasEquivalentTransition");
951 if (vtz_new
!= NULL
) {
962 * Write out simple time zone rules from an OlsonTimeZone at various time into VTIMEZONE
963 * format and create a new VTimeZone from the VTIMEZONE data, then make sure the raw offset
964 * and DST savings are same in these two time zones.
967 TimeZoneRuleTest::TestVTimeZoneSimpleWrite(void) {
968 const int32_t TESTDATES
[][3] = {
969 {2006, UCAL_JANUARY
, 1},
970 {2006, UCAL_MARCH
, 15},
971 {2006, UCAL_MARCH
, 31},
972 {2006, UCAL_OCTOBER
, 25},
973 {2006, UCAL_NOVEMBER
, 1},
974 {2006, UCAL_NOVEMBER
, 5},
975 {2007, UCAL_JANUARY
, 1},
979 UErrorCode status
= U_ZERO_ERROR
;
980 TestZIDEnumeration
tzenum(!quick
);
982 const UnicodeString
*tzid
= tzenum
.snext(status
);
986 if (U_FAILURE(status
)) {
987 errln("FAIL: error returned while enumerating timezone IDs.");
990 VTimeZone
*vtz_org
= VTimeZone::createVTimeZoneByID(*tzid
);
991 VTimeZone
*vtz_new
= NULL
;
992 UnicodeString vtzdata
;
994 for (int32_t i
= 0; TESTDATES
[i
][0] != 0; i
++) {
995 // Write out VTIMEZONE
996 UDate time
= getUTCMillis(TESTDATES
[i
][0], TESTDATES
[i
][1], TESTDATES
[i
][2]);
997 vtz_org
->writeSimple(time
, vtzdata
, status
);
998 if (U_FAILURE(status
)) {
999 errln((UnicodeString
)"FAIL: error returned while writing simple time zone rules for " +
1000 *tzid
+ " into VTIMEZONE format at " + dateToString(time
));
1002 // Read VTIMEZONE data
1003 vtz_new
= VTimeZone::createVTimeZone(vtzdata
, status
);
1004 if (U_FAILURE(status
)) {
1005 errln((UnicodeString
)"FAIL: error returned while reading simple VTIMEZONE data for " + *tzid
1006 + " at " + dateToString(time
));
1008 // Check equivalency
1011 vtz_org
->getOffset(time
, FALSE
, raw0
, dst0
, status
);
1012 vtz_new
->getOffset(time
, FALSE
, raw1
, dst1
, status
);
1013 if (U_SUCCESS(status
)) {
1014 if (raw0
!= raw1
|| dst0
!= dst1
) {
1015 errln("FAIL: VTimeZone writeSimple for " + *tzid
+ " at "
1016 + dateToString(time
) + " failed to the round trip.");
1019 errln("FAIL: getOffset returns error status");
1023 if (vtz_new
!= NULL
) {
1033 * Write out time zone rules of OlsonTimeZone into VTIMEZONE format with RFC2445 header TZURL and
1034 * LAST-MODIFIED, create a new VTimeZone from the VTIMEZONE data to see if the headers are preserved.
1037 TimeZoneRuleTest::TestVTimeZoneHeaderProps(void) {
1038 const UnicodeString
TESTURL1("http://source.icu-project.org");
1039 const UnicodeString
TESTURL2("http://www.ibm.com");
1041 UErrorCode status
= U_ZERO_ERROR
;
1042 UnicodeString tzurl
;
1044 UDate lastmod
= getUTCMillis(2007, UCAL_JUNE
, 1);
1045 VTimeZone
*vtz
= VTimeZone::createVTimeZoneByID("America/Chicago");
1046 vtz
->setTZURL(TESTURL1
);
1047 vtz
->setLastModified(lastmod
);
1049 // Roundtrip conversion
1050 UnicodeString vtzdata
;
1051 vtz
->write(vtzdata
, status
);
1052 VTimeZone
*newvtz1
= NULL
;
1053 if (U_FAILURE(status
)) {
1054 errln("FAIL: error returned while writing VTIMEZONE data 1");
1058 newvtz1
= VTimeZone::createVTimeZone(vtzdata
, status
);
1059 if (U_FAILURE(status
)) {
1060 errln("FAIL: error returned while loading VTIMEZONE data 1");
1062 // Check if TZURL and LAST-MODIFIED properties are preserved
1063 newvtz1
->getTZURL(tzurl
);
1064 if (tzurl
!= TESTURL1
) {
1065 errln("FAIL: TZURL 1 was not preserved");
1067 vtz
->getLastModified(lmod
);
1068 if (lastmod
!= lmod
) {
1069 errln("FAIL: LAST-MODIFIED was not preserved");
1073 if (U_SUCCESS(status
)) {
1074 // Set different tzurl
1075 newvtz1
->setTZURL(TESTURL2
);
1077 // Second roundtrip, with a cutover
1078 newvtz1
->write(vtzdata
, status
);
1079 if (U_FAILURE(status
)) {
1080 errln("FAIL: error returned while writing VTIMEZONE data 2");
1082 VTimeZone
*newvtz2
= VTimeZone::createVTimeZone(vtzdata
, status
);
1083 if (U_FAILURE(status
)) {
1084 errln("FAIL: error returned while loading VTIMEZONE data 2");
1086 // Check if TZURL and LAST-MODIFIED properties are preserved
1087 newvtz2
->getTZURL(tzurl
);
1088 if (tzurl
!= TESTURL2
) {
1089 errln("FAIL: TZURL was not preserved in the second roundtrip");
1091 vtz
->getLastModified(lmod
);
1092 if (lastmod
!= lmod
) {
1093 errln("FAIL: LAST-MODIFIED was not preserved in the second roundtrip");
1104 * Extract simple rules from an OlsonTimeZone and make sure the rule format matches
1105 * the expected format.
1108 TimeZoneRuleTest::TestGetSimpleRules(void) {
1109 UDate testTimes
[] = {
1110 getUTCMillis(1970, UCAL_JANUARY
, 1),
1111 getUTCMillis(2000, UCAL_MARCH
, 31),
1112 getUTCMillis(2005, UCAL_JULY
, 1),
1113 getUTCMillis(2010, UCAL_NOVEMBER
, 1),
1115 int32_t numTimes
= sizeof(testTimes
)/sizeof(UDate
);
1116 UErrorCode status
= U_ZERO_ERROR
;
1117 TestZIDEnumeration
tzenum(!quick
);
1118 InitialTimeZoneRule
*initial
;
1119 AnnualTimeZoneRule
*std
, *dst
;
1120 for (int32_t i
= 0; i
< numTimes
; i
++) {
1122 const UnicodeString
*tzid
= tzenum
.snext(status
);
1126 if (U_FAILURE(status
)) {
1127 errln("FAIL: error returned while enumerating timezone IDs.");
1130 BasicTimeZone
*tz
= (BasicTimeZone
*)TimeZone::createTimeZone(*tzid
);
1133 tz
->getSimpleRulesNear(testTimes
[i
], initial
, std
, dst
, status
);
1134 if (U_FAILURE(status
)) {
1135 errln("FAIL: getSimpleRules failed.");
1138 if (initial
== NULL
) {
1139 errln("FAIL: initial rule must not be NULL");
1141 } else if (!((std
== NULL
&& dst
== NULL
) || (std
!= NULL
&& dst
!= NULL
))) {
1142 errln("FAIL: invalid std/dst pair.");
1146 const DateTimeRule
*dtr
= std
->getRule();
1147 if (dtr
->getDateRuleType() != DateTimeRule::DOW
) {
1148 errln("FAIL: simple std rull must use DateTimeRule::DOW as date rule.");
1151 if (dtr
->getTimeRuleType() != DateTimeRule::WALL_TIME
) {
1152 errln("FAIL: simple std rull must use DateTimeRule::WALL_TIME as time rule.");
1155 dtr
= dst
->getRule();
1156 if (dtr
->getDateRuleType() != DateTimeRule::DOW
) {
1157 errln("FAIL: simple dst rull must use DateTimeRule::DOW as date rule.");
1160 if (dtr
->getTimeRuleType() != DateTimeRule::WALL_TIME
) {
1161 errln("FAIL: simple dst rull must use DateTimeRule::WALL_TIME as time rule.");
1165 // Create an RBTZ from the rules and compare the offsets at the date
1166 RuleBasedTimeZone
*rbtz
= new RuleBasedTimeZone(*tzid
, initial
);
1168 rbtz
->addTransitionRule(std
, status
);
1169 if (U_FAILURE(status
)) {
1170 errln("FAIL: couldn't add std rule.");
1172 rbtz
->addTransitionRule(dst
, status
);
1173 if (U_FAILURE(status
)) {
1174 errln("FAIL: couldn't add dst rule.");
1177 rbtz
->complete(status
);
1178 if (U_FAILURE(status
)) {
1179 errln("FAIL: couldn't complete rbtz for " + *tzid
);
1182 int32_t raw0
, dst0
, raw1
, dst1
;
1183 tz
->getOffset(testTimes
[i
], FALSE
, raw0
, dst0
, status
);
1184 if (U_FAILURE(status
)) {
1185 errln("FAIL: couldn't get offsets from tz for " + *tzid
);
1187 rbtz
->getOffset(testTimes
[i
], FALSE
, raw1
, dst1
, status
);
1188 if (U_FAILURE(status
)) {
1189 errln("FAIL: couldn't get offsets from rbtz for " + *tzid
);
1191 if (raw0
!= raw1
|| dst0
!= dst1
) {
1192 errln("FAIL: rbtz created by simple rule does not match the original tz for tzid " + *tzid
);
1201 * API coverage tests for TimeZoneRule
1204 TimeZoneRuleTest::TestTimeZoneRuleCoverage(void) {
1205 UDate time1
= getUTCMillis(2005, UCAL_JULY
, 4);
1206 UDate time2
= getUTCMillis(2015, UCAL_JULY
, 4);
1207 UDate time3
= getUTCMillis(1950, UCAL_JULY
, 4);
1209 DateTimeRule
*dtr1
= new DateTimeRule(UCAL_FEBRUARY
, 29, UCAL_SUNDAY
, FALSE
,
1210 3*HOUR
, DateTimeRule::WALL_TIME
); // Last Sunday on or before Feb 29, at 3 AM, wall time
1211 DateTimeRule
*dtr2
= new DateTimeRule(UCAL_MARCH
, 11, 2*HOUR
,
1212 DateTimeRule::STANDARD_TIME
); // Mar 11, at 2 AM, standard time
1213 DateTimeRule
*dtr3
= new DateTimeRule(UCAL_OCTOBER
, -1, UCAL_SATURDAY
,
1214 6*HOUR
, DateTimeRule::UTC_TIME
); //Last Saturday in Oct, at 6 AM, UTC
1215 DateTimeRule
*dtr4
= new DateTimeRule(UCAL_MARCH
, 8, UCAL_SUNDAY
, TRUE
,
1216 2*HOUR
, DateTimeRule::WALL_TIME
); // First Sunday on or after Mar 8, at 2 AM, wall time
1218 AnnualTimeZoneRule
*a1
= new AnnualTimeZoneRule("a1", -3*HOUR
, 1*HOUR
, *dtr1
,
1219 2000, AnnualTimeZoneRule::MAX_YEAR
);
1220 AnnualTimeZoneRule
*a2
= new AnnualTimeZoneRule("a2", -3*HOUR
, 1*HOUR
, *dtr1
,
1221 2000, AnnualTimeZoneRule::MAX_YEAR
);
1222 AnnualTimeZoneRule
*a3
= new AnnualTimeZoneRule("a3", -3*HOUR
, 1*HOUR
, *dtr1
,
1225 InitialTimeZoneRule
*i1
= new InitialTimeZoneRule("i1", -3*HOUR
, 0);
1226 InitialTimeZoneRule
*i2
= new InitialTimeZoneRule("i2", -3*HOUR
, 0);
1227 InitialTimeZoneRule
*i3
= new InitialTimeZoneRule("i3", -3*HOUR
, 1*HOUR
);
1229 UDate trtimes1
[] = {0.0};
1230 UDate trtimes2
[] = {0.0, 10000000.0};
1232 TimeArrayTimeZoneRule
*t1
= new TimeArrayTimeZoneRule("t1", -3*HOUR
, 0, trtimes1
, 1, DateTimeRule::UTC_TIME
);
1233 TimeArrayTimeZoneRule
*t2
= new TimeArrayTimeZoneRule("t2", -3*HOUR
, 0, trtimes1
, 1, DateTimeRule::UTC_TIME
);
1234 TimeArrayTimeZoneRule
*t3
= new TimeArrayTimeZoneRule("t3", -3*HOUR
, 0, trtimes2
, 2, DateTimeRule::UTC_TIME
);
1235 TimeArrayTimeZoneRule
*t4
= new TimeArrayTimeZoneRule("t4", -3*HOUR
, 0, trtimes1
, 1, DateTimeRule::STANDARD_TIME
);
1236 TimeArrayTimeZoneRule
*t5
= new TimeArrayTimeZoneRule("t5", -4*HOUR
, 1*HOUR
, trtimes1
, 1, DateTimeRule::WALL_TIME
);
1238 // DateTimeRule::operator=/clone
1239 DateTimeRule
dtr0(UCAL_MAY
, 31, 2*HOUR
, DateTimeRule::WALL_TIME
);
1240 if (dtr0
== *dtr1
|| !(dtr0
!= *dtr1
)) {
1241 errln("FAIL: DateTimeRule dtr0 is not equal to dtr1, but got wrong result");
1244 if (dtr0
!= *dtr1
|| !(dtr0
== *dtr1
)) {
1245 errln("FAIL: DateTimeRule dtr0 is equal to dtr1, but got wrong result");
1247 DateTimeRule
*dtr0c
= dtr0
.clone();
1248 if (*dtr0c
!= *dtr1
|| !(*dtr0c
== *dtr1
)) {
1249 errln("FAIL: DateTimeRule dtr0c is equal to dtr1, but got wrong result");
1253 // AnnualTimeZonerule::operator=/clone
1254 AnnualTimeZoneRule
a0("a0", 5*HOUR
, 1*HOUR
, *dtr1
, 1990, AnnualTimeZoneRule::MAX_YEAR
);
1255 if (a0
== *a1
|| !(a0
!= *a1
)) {
1256 errln("FAIL: AnnualTimeZoneRule a0 is not equal to a1, but got wrong result");
1259 if (a0
!= *a1
|| !(a0
== *a1
)) {
1260 errln("FAIL: AnnualTimeZoneRule a0 is equal to a1, but got wrong result");
1262 AnnualTimeZoneRule
*a0c
= a0
.clone();
1263 if (*a0c
!= *a1
|| !(*a0c
== *a1
)) {
1264 errln("FAIL: AnnualTimeZoneRule a0c is equal to a1, but got wrong result");
1268 // AnnualTimeZoneRule::getRule
1269 if (*(a1
->getRule()) != *(a2
->getRule())) {
1270 errln("FAIL: The same DateTimeRule must be returned from AnnualTimeZoneRule a1 and a2");
1273 // AnnualTimeZoneRule::getStartYear
1274 int32_t startYear
= a1
->getStartYear();
1275 if (startYear
!= 2000) {
1276 errln((UnicodeString
)"FAIL: The start year of AnnualTimeZoneRule a1 must be 2000 - returned: " + startYear
);
1279 // AnnualTimeZoneRule::getEndYear
1280 int32_t endYear
= a1
->getEndYear();
1281 if (endYear
!= AnnualTimeZoneRule::MAX_YEAR
) {
1282 errln((UnicodeString
)"FAIL: The start year of AnnualTimeZoneRule a1 must be MAX_YEAR - returned: " + endYear
);
1284 endYear
= a3
->getEndYear();
1285 if (endYear
!= 2010) {
1286 errln((UnicodeString
)"FAIL: The start year of AnnualTimeZoneRule a3 must be 2010 - returned: " + endYear
);
1289 // AnnualTimeZone::getStartInYear
1292 b1
= a1
->getStartInYear(2005, -3*HOUR
, 0, d1
);
1293 b2
= a3
->getStartInYear(2005, -3*HOUR
, 0, d2
);
1294 if (!b1
|| !b2
|| d1
!= d2
) {
1295 errln("FAIL: AnnualTimeZoneRule::getStartInYear did not work as expected");
1297 b2
= a3
->getStartInYear(2015, -3*HOUR
, 0, d2
);
1299 errln("FAIL: AnnualTimeZoneRule::getStartInYear returned TRUE for 2015 which is out of rule range");
1302 // AnnualTimeZone::getFirstStart
1303 b1
= a1
->getFirstStart(-3*HOUR
, 0, d1
);
1304 b2
= a1
->getFirstStart(-4*HOUR
, 1*HOUR
, d2
);
1305 if (!b1
|| !b2
|| d1
!= d2
) {
1306 errln("FAIL: The same start time should be returned by getFirstStart");
1309 // AnnualTimeZone::getFinalStart
1310 b1
= a1
->getFinalStart(-3*HOUR
, 0, d1
);
1312 errln("FAIL: getFinalStart returned TRUE for a1");
1314 b1
= a1
->getStartInYear(2010, -3*HOUR
, 0, d1
);
1315 b2
= a3
->getFinalStart(-3*HOUR
, 0, d2
);
1316 if (!b1
|| !b2
|| d1
!= d2
) {
1317 errln("FAIL: Bad date is returned by getFinalStart");
1320 // AnnualTimeZone::getNextStart / getPreviousStart
1321 b1
= a1
->getNextStart(time1
, -3*HOUR
, 0, FALSE
, d1
);
1323 errln("FAIL: getNextStart returned FALSE for ai");
1325 b2
= a1
->getPreviousStart(d1
, -3*HOUR
, 0, TRUE
, d2
);
1326 if (!b2
|| d1
!= d2
) {
1327 errln("FAIL: Bad Date is returned by getPreviousStart");
1330 b1
= a3
->getNextStart(time2
, -3*HOUR
, 0, FALSE
, d1
);
1332 dataerrln("FAIL: getNextStart must return FALSE when no start time is available after the base time");
1334 b1
= a3
->getFinalStart(-3*HOUR
, 0, d1
);
1335 b2
= a3
->getPreviousStart(time2
, -3*HOUR
, 0, FALSE
, d2
);
1336 if (!b1
|| !b2
|| d1
!= d2
) {
1337 dataerrln("FAIL: getPreviousStart does not match with getFinalStart after the end year");
1340 // AnnualTimeZone::isEquavalentTo
1341 if (!a1
->isEquivalentTo(*a2
)) {
1342 errln("FAIL: AnnualTimeZoneRule a1 is equivalent to a2, but returned FALSE");
1344 if (a1
->isEquivalentTo(*a3
)) {
1345 errln("FAIL: AnnualTimeZoneRule a1 is not equivalent to a3, but returned TRUE");
1347 if (!a1
->isEquivalentTo(*a1
)) {
1348 errln("FAIL: AnnualTimeZoneRule a1 is equivalent to itself, but returned FALSE");
1350 if (a1
->isEquivalentTo(*t1
)) {
1351 errln("FAIL: AnnualTimeZoneRule is not equivalent to TimeArrayTimeZoneRule, but returned TRUE");
1354 // InitialTimezoneRule::operator=/clone
1355 InitialTimeZoneRule
i0("i0", 10*HOUR
, 0);
1356 if (i0
== *i1
|| !(i0
!= *i1
)) {
1357 errln("FAIL: InitialTimeZoneRule i0 is not equal to i1, but got wrong result");
1360 if (i0
!= *i1
|| !(i0
== *i1
)) {
1361 errln("FAIL: InitialTimeZoneRule i0 is equal to i1, but got wrong result");
1363 InitialTimeZoneRule
*i0c
= i0
.clone();
1364 if (*i0c
!= *i1
|| !(*i0c
== *i1
)) {
1365 errln("FAIL: InitialTimeZoneRule i0c is equal to i1, but got wrong result");
1369 // InitialTimeZoneRule::isEquivalentRule
1370 if (!i1
->isEquivalentTo(*i2
)) {
1371 errln("FAIL: InitialTimeZoneRule i1 is equivalent to i2, but returned FALSE");
1373 if (i1
->isEquivalentTo(*i3
)) {
1374 errln("FAIL: InitialTimeZoneRule i1 is not equivalent to i3, but returned TRUE");
1376 if (i1
->isEquivalentTo(*a1
)) {
1377 errln("FAIL: An InitialTimeZoneRule is not equivalent to an AnnualTimeZoneRule, but returned TRUE");
1380 // InitialTimeZoneRule::getFirstStart/getFinalStart/getNextStart/getPreviousStart
1381 b1
= i1
->getFirstStart(0, 0, d1
);
1383 errln("FAIL: InitialTimeZone::getFirstStart returned TRUE");
1385 b1
= i1
->getFinalStart(0, 0, d1
);
1387 errln("FAIL: InitialTimeZone::getFinalStart returned TRUE");
1389 b1
= i1
->getNextStart(time1
, 0, 0, FALSE
, d1
);
1391 errln("FAIL: InitialTimeZone::getNextStart returned TRUE");
1393 b1
= i1
->getPreviousStart(time1
, 0, 0, FALSE
, d1
);
1395 errln("FAIL: InitialTimeZone::getPreviousStart returned TRUE");
1398 // TimeArrayTimeZoneRule::operator=/clone
1399 TimeArrayTimeZoneRule
t0("t0", 4*HOUR
, 0, trtimes1
, 1, DateTimeRule::UTC_TIME
);
1400 if (t0
== *t1
|| !(t0
!= *t1
)) {
1401 errln("FAIL: TimeArrayTimeZoneRule t0 is not equal to t1, but got wrong result");
1404 if (t0
!= *t1
|| !(t0
== *t1
)) {
1405 errln("FAIL: TimeArrayTimeZoneRule t0 is equal to t1, but got wrong result");
1407 TimeArrayTimeZoneRule
*t0c
= t0
.clone();
1408 if (*t0c
!= *t1
|| !(*t0c
== *t1
)) {
1409 errln("FAIL: TimeArrayTimeZoneRule t0c is equal to t1, but got wrong result");
1413 // TimeArrayTimeZoneRule::countStartTimes
1414 if (t1
->countStartTimes() != 1) {
1415 errln("FAIL: Bad start time count is returned by TimeArrayTimeZoneRule::countStartTimes");
1418 // TimeArrayTimeZoneRule::getStartTimeAt
1419 b1
= t1
->getStartTimeAt(-1, d1
);
1421 errln("FAIL: TimeArrayTimeZoneRule::getStartTimeAt returned TRUE for index -1");
1423 b1
= t1
->getStartTimeAt(0, d1
);
1424 if (!b1
|| d1
!= trtimes1
[0]) {
1425 errln("FAIL: TimeArrayTimeZoneRule::getStartTimeAt returned incorrect result for index 0");
1427 b1
= t1
->getStartTimeAt(1, d1
);
1429 errln("FAIL: TimeArrayTimeZoneRule::getStartTimeAt returned TRUE for index 1");
1432 // TimeArrayTimeZoneRule::getTimeType
1433 if (t1
->getTimeType() != DateTimeRule::UTC_TIME
) {
1434 errln("FAIL: TimeArrayTimeZoneRule t1 uses UTC_TIME, but different type is returned");
1436 if (t4
->getTimeType() != DateTimeRule::STANDARD_TIME
) {
1437 errln("FAIL: TimeArrayTimeZoneRule t4 uses STANDARD_TIME, but different type is returned");
1439 if (t5
->getTimeType() != DateTimeRule::WALL_TIME
) {
1440 errln("FAIL: TimeArrayTimeZoneRule t5 uses WALL_TIME, but different type is returned");
1443 // TimeArrayTimeZoneRule::getFirstStart/getFinalStart
1444 b1
= t1
->getFirstStart(0, 0, d1
);
1445 if (!b1
|| d1
!= trtimes1
[0]) {
1446 errln("FAIL: Bad first start time returned from TimeArrayTimeZoneRule t1");
1448 b1
= t1
->getFinalStart(0, 0, d1
);
1449 if (!b1
|| d1
!= trtimes1
[0]) {
1450 errln("FAIL: Bad final start time returned from TimeArrayTimeZoneRule t1");
1452 b1
= t4
->getFirstStart(-4*HOUR
, 1*HOUR
, d1
);
1453 if (!b1
|| d1
!= (trtimes1
[0] + 4*HOUR
)) {
1454 errln("FAIL: Bad first start time returned from TimeArrayTimeZoneRule t4");
1456 b1
= t5
->getFirstStart(-4*HOUR
, 1*HOUR
, d1
);
1457 if (!b1
|| d1
!= (trtimes1
[0] + 3*HOUR
)) {
1458 errln("FAIL: Bad first start time returned from TimeArrayTimeZoneRule t5");
1461 // TimeArrayTimeZoneRule::getNextStart/getPreviousStart
1462 b1
= t3
->getNextStart(time1
, -3*HOUR
, 1*HOUR
, FALSE
, d1
);
1464 dataerrln("FAIL: getNextStart returned TRUE after the final transition for t3");
1466 b1
= t3
->getPreviousStart(time1
, -3*HOUR
, 1*HOUR
, FALSE
, d1
);
1467 if (!b1
|| d1
!= trtimes2
[1]) {
1468 dataerrln("FAIL: Bad start time returned by getPreviousStart for t3");
1470 b2
= t3
->getPreviousStart(d1
, -3*HOUR
, 1*HOUR
, FALSE
, d2
);
1471 if (!b2
|| d2
!= trtimes2
[0]) {
1472 errln("FAIL: Bad start time returned by getPreviousStart for t3");
1475 b1
= t3
->getPreviousStart(time3
, -3*HOUR
, 1*HOUR
, FALSE
, d1
); //time3 - year 1950, no result expected
1477 errln("FAIL: getPreviousStart returned TRUE before the first transition for t3");
1480 // TimeArrayTimeZoneRule::isEquivalentTo
1481 if (!t1
->isEquivalentTo(*t2
)) {
1482 errln("FAIL: TimeArrayTimeZoneRule t1 is equivalent to t2, but returned FALSE");
1484 if (t1
->isEquivalentTo(*t3
)) {
1485 errln("FAIL: TimeArrayTimeZoneRule t1 is not equivalent to t3, but returned TRUE");
1487 if (t1
->isEquivalentTo(*t4
)) {
1488 errln("FAIL: TimeArrayTimeZoneRule t1 is not equivalent to t4, but returned TRUE");
1490 if (t1
->isEquivalentTo(*a1
)) {
1491 errln("FAIL: TimeArrayTimeZoneRule is not equivalent to AnnualTimeZoneRule, but returned TRUE");
1512 * API coverage test for BasicTimeZone APIs in SimpleTimeZone
1515 TimeZoneRuleTest::TestSimpleTimeZoneCoverage(void) {
1516 UDate time1
= getUTCMillis(1990, UCAL_JUNE
, 1);
1517 UDate time2
= getUTCMillis(2000, UCAL_JUNE
, 1);
1519 TimeZoneTransition tzt1
, tzt2
;
1520 UBool avail1
, avail2
;
1521 UErrorCode status
= U_ZERO_ERROR
;
1522 const TimeZoneRule
*trrules
[2];
1523 const InitialTimeZoneRule
*ir
= NULL
;
1526 // BasicTimeZone API implementation in SimpleTimeZone
1527 SimpleTimeZone
*stz1
= new SimpleTimeZone(-5*HOUR
, "GMT-5");
1529 avail1
= stz1
->getNextTransition(time1
, FALSE
, tzt1
);
1531 errln("FAIL: No transition must be returned by getNextTranstion for SimpleTimeZone with no DST rule");
1533 avail1
= stz1
->getPreviousTransition(time1
, FALSE
, tzt1
);
1535 errln("FAIL: No transition must be returned by getPreviousTransition for SimpleTimeZone with no DST rule");
1538 numTzRules
= stz1
->countTransitionRules(status
);
1539 if (U_FAILURE(status
)) {
1540 errln("FAIL: countTransitionRules failed");
1542 if (numTzRules
!= 0) {
1543 errln((UnicodeString
)"FAIL: countTransitionRules returned " + numTzRules
);
1546 stz1
->getTimeZoneRules(ir
, trrules
, numTzRules
, status
);
1547 if (U_FAILURE(status
)) {
1548 errln("FAIL: getTimeZoneRules failed");
1550 if (numTzRules
!= 0) {
1551 errln("FAIL: Incorrect transition rule count");
1553 if (ir
== NULL
|| ir
->getRawOffset() != stz1
->getRawOffset()) {
1554 errln("FAIL: Bad initial time zone rule");
1558 stz1
->setStartRule(UCAL_MARCH
, 11, 2*HOUR
, status
); // March 11
1559 stz1
->setEndRule(UCAL_NOVEMBER
, 1, UCAL_SUNDAY
, 2*HOUR
, status
); // First Sunday in November
1560 if (U_FAILURE(status
)) {
1561 errln("FAIL: Failed to set DST rules in a SimpleTimeZone");
1564 avail1
= stz1
->getNextTransition(time1
, FALSE
, tzt1
);
1566 errln("FAIL: Non-null transition must be returned by getNextTranstion for SimpleTimeZone with a DST rule");
1568 avail1
= stz1
->getPreviousTransition(time1
, FALSE
, tzt1
);
1570 errln("FAIL: Non-null transition must be returned by getPreviousTransition for SimpleTimeZone with a DST rule");
1573 numTzRules
= stz1
->countTransitionRules(status
);
1574 if (U_FAILURE(status
)) {
1575 errln("FAIL: countTransitionRules failed");
1577 if (numTzRules
!= 2) {
1578 errln((UnicodeString
)"FAIL: countTransitionRules returned " + numTzRules
);
1584 stz1
->getTimeZoneRules(ir
, trrules
, numTzRules
, status
);
1585 if (U_FAILURE(status
)) {
1586 errln("FAIL: getTimeZoneRules failed");
1588 if (numTzRules
!= 2) {
1589 errln("FAIL: Incorrect transition rule count");
1591 if (ir
== NULL
|| ir
->getRawOffset() != stz1
->getRawOffset()) {
1592 errln("FAIL: Bad initial time zone rule");
1594 if (trrules
[0] == NULL
|| trrules
[0]->getRawOffset() != stz1
->getRawOffset()) {
1595 errln("FAIL: Bad transition rule 0");
1597 if (trrules
[1] == NULL
|| trrules
[1]->getRawOffset() != stz1
->getRawOffset()) {
1598 errln("FAIL: Bad transition rule 1");
1601 // Set DST start year
1602 stz1
->setStartYear(2007);
1603 avail1
= stz1
->getPreviousTransition(time1
, FALSE
, tzt1
);
1605 errln("FAIL: No transition must be returned before 1990");
1607 avail1
= stz1
->getNextTransition(time1
, FALSE
, tzt1
); // transition after 1990-06-01
1608 avail2
= stz1
->getNextTransition(time2
, FALSE
, tzt2
); // transition after 2000-06-01
1609 if (!avail1
|| !avail2
|| tzt1
!= tzt2
) {
1610 errln("FAIL: Bad transition returned by SimpleTimeZone::getNextTransition");
1616 * API coverage test for VTimeZone
1619 TimeZoneRuleTest::TestVTimeZoneCoverage(void) {
1620 UErrorCode status
= U_ZERO_ERROR
;
1621 UnicodeString
TZID("Europe/Moscow");
1623 BasicTimeZone
*otz
= (BasicTimeZone
*)TimeZone::createTimeZone(TZID
);
1624 VTimeZone
*vtz
= VTimeZone::createVTimeZoneByID(TZID
);
1626 // getOffset(era, year, month, day, dayOfWeek, milliseconds, ec)
1627 int32_t offset1
= otz
->getOffset(GregorianCalendar::AD
, 2007, UCAL_JULY
, 1, UCAL_SUNDAY
, 0, status
);
1628 if (U_FAILURE(status
)) {
1629 errln("FAIL: getOffset(7 args) failed for otz");
1631 int32_t offset2
= vtz
->getOffset(GregorianCalendar::AD
, 2007, UCAL_JULY
, 1, UCAL_SUNDAY
, 0, status
);
1632 if (U_FAILURE(status
)) {
1633 errln("FAIL: getOffset(7 args) failed for vtz");
1635 if (offset1
!= offset2
) {
1636 errln("FAIL: getOffset(7 args) returned different results in VTimeZone and OlsonTimeZone");
1639 // getOffset(era, year, month, day, dayOfWeek, milliseconds, monthLength, ec)
1640 offset1
= otz
->getOffset(GregorianCalendar::AD
, 2007, UCAL_JULY
, 1, UCAL_SUNDAY
, 0, 31, status
);
1641 if (U_FAILURE(status
)) {
1642 errln("FAIL: getOffset(8 args) failed for otz");
1644 offset2
= vtz
->getOffset(GregorianCalendar::AD
, 2007, UCAL_JULY
, 1, UCAL_SUNDAY
, 0, 31, status
);
1645 if (U_FAILURE(status
)) {
1646 errln("FAIL: getOffset(8 args) failed for vtz");
1648 if (offset1
!= offset2
) {
1649 errln("FAIL: getOffset(8 args) returned different results in VTimeZone and OlsonTimeZone");
1653 // getOffset(date, local, rawOffset, dstOffset, ec)
1654 UDate t
= Calendar::getNow();
1655 int32_t rawOffset1
, dstSavings1
;
1656 int32_t rawOffset2
, dstSavings2
;
1658 otz
->getOffset(t
, FALSE
, rawOffset1
, dstSavings1
, status
);
1659 if (U_FAILURE(status
)) {
1660 errln("FAIL: getOffset(5 args) failed for otz");
1662 vtz
->getOffset(t
, FALSE
, rawOffset2
, dstSavings2
, status
);
1663 if (U_FAILURE(status
)) {
1664 errln("FAIL: getOffset(5 args) failed for vtz");
1666 if (rawOffset1
!= rawOffset2
|| dstSavings1
!= dstSavings2
) {
1667 errln("FAIL: getOffset(long,boolean,int[]) returned different results in VTimeZone and OlsonTimeZone");
1671 if (otz
->getRawOffset() != vtz
->getRawOffset()) {
1672 errln("FAIL: getRawOffset returned different results in VTimeZone and OlsonTimeZone");
1676 UBool inDst1
, inDst2
;
1677 inDst1
= otz
->inDaylightTime(t
, status
);
1678 if (U_FAILURE(status
)) {
1679 dataerrln("FAIL: inDaylightTime failed for otz: %s", u_errorName(status
));
1681 inDst2
= vtz
->inDaylightTime(t
, status
);
1682 if (U_FAILURE(status
)) {
1683 dataerrln("FAIL: inDaylightTime failed for vtz: %s", u_errorName(status
));
1685 if (inDst1
!= inDst2
) {
1686 errln("FAIL: inDaylightTime returned different results in VTimeZone and OlsonTimeZone");
1690 if (otz
->useDaylightTime() != vtz
->useDaylightTime()) {
1691 errln("FAIL: useDaylightTime returned different results in VTimeZone and OlsonTimeZone");
1695 const int32_t RAW
= -10*HOUR
;
1696 VTimeZone
*tmpvtz
= (VTimeZone
*)vtz
->clone();
1697 tmpvtz
->setRawOffset(RAW
);
1698 if (tmpvtz
->getRawOffset() != RAW
) {
1699 logln("setRawOffset is implemented in VTimeZone");
1703 UBool bSame
= otz
->hasSameRules(*vtz
);
1704 logln((UnicodeString
)"OlsonTimeZone::hasSameRules(VTimeZone) should return FALSE always for now - actual: " + bSame
);
1706 // getTZURL/setTZURL
1707 UnicodeString
TZURL("http://icu-project.org/timezone");
1709 if (vtz
->getTZURL(url
)) {
1710 errln("FAIL: getTZURL returned TRUE");
1712 vtz
->setTZURL(TZURL
);
1713 if (!vtz
->getTZURL(url
) || url
!= TZURL
) {
1714 errln("FAIL: URL returned by getTZURL does not match the one set by setTZURL");
1717 // getLastModified/setLastModified
1719 if (vtz
->getLastModified(lastmod
)) {
1720 errln("FAIL: getLastModified returned TRUE");
1722 vtz
->setLastModified(t
);
1723 if (!vtz
->getLastModified(lastmod
) || lastmod
!= t
) {
1724 errln("FAIL: Date returned by getLastModified does not match the one set by setLastModified");
1727 // getNextTransition/getPreviousTransition
1728 UDate base
= getUTCMillis(2007, UCAL_JULY
, 1);
1729 TimeZoneTransition tzt1
, tzt2
;
1730 UBool btr1
= otz
->getNextTransition(base
, TRUE
, tzt1
);
1731 UBool btr2
= vtz
->getNextTransition(base
, TRUE
, tzt2
);
1732 if (!btr1
|| !btr2
|| tzt1
!= tzt2
) {
1733 dataerrln("FAIL: getNextTransition returned different results in VTimeZone and OlsonTimeZone");
1735 btr1
= otz
->getPreviousTransition(base
, FALSE
, tzt1
);
1736 btr2
= vtz
->getPreviousTransition(base
, FALSE
, tzt2
);
1737 if (!btr1
|| !btr2
|| tzt1
!= tzt2
) {
1738 dataerrln("FAIL: getPreviousTransition returned different results in VTimeZone and OlsonTimeZone");
1741 // TimeZoneTransition constructor/clone
1742 TimeZoneTransition
*tzt1c
= tzt1
.clone();
1743 if (*tzt1c
!= tzt1
|| !(*tzt1c
== tzt1
)) {
1744 errln("FAIL: TimeZoneTransition tzt1c is equal to tzt1, but got wrong result");
1747 TimeZoneTransition
tzt3(tzt1
);
1748 if (tzt3
!= tzt1
|| !(tzt3
== tzt1
)) {
1749 errln("FAIL: TimeZoneTransition tzt3 is equal to tzt1, but got wrong result");
1752 // hasEquivalentTransitions
1753 UDate time1
= getUTCMillis(1950, UCAL_JANUARY
, 1);
1754 UDate time2
= getUTCMillis(2020, UCAL_JANUARY
, 1);
1755 UBool equiv
= vtz
->hasEquivalentTransitions(*otz
, time1
, time2
, FALSE
, status
);
1756 if (U_FAILURE(status
)) {
1757 dataerrln("FAIL: hasEquivalentTransitions failed for vtz/otz: %s", u_errorName(status
));
1760 dataerrln("FAIL: hasEquivalentTransitons returned false for the same time zone");
1763 // operator=/operator==/operator!=
1764 VTimeZone
*vtz1
= VTimeZone::createVTimeZoneByID("America/Los_Angeles");
1765 if (*vtz1
== *vtz
|| !(*vtz1
!= *vtz
)) {
1766 errln("FAIL: VTimeZone vtz1 is not equal to vtz, but got wrong result");
1769 if (*vtz1
!= *vtz
|| !(*vtz1
== *vtz
)) {
1770 errln("FAIL: VTimeZone vtz1 is equal to vtz, but got wrong result");
1773 // Creation from BasicTimeZone
1775 status
= U_ZERO_ERROR
;
1776 VTimeZone
*vtzFromBasic
= NULL
;
1777 SimpleTimeZone
*simpleTZ
= new SimpleTimeZone(28800000, "Asia/Singapore");
1778 simpleTZ
->setStartYear(1970);
1779 simpleTZ
->setStartRule(0, // month
1783 simpleTZ
->setEndRule(1, 1, 0, status
);
1784 if (U_FAILURE(status
)) {
1785 errln("File %s, line %d, failed with status = %s", __FILE__
, __LINE__
, u_errorName(status
));
1786 goto end_basic_tz_test
;
1788 vtzFromBasic
= VTimeZone::createVTimeZoneFromBasicTimeZone(*simpleTZ
, status
);
1789 if (U_FAILURE(status
) || vtzFromBasic
== NULL
) {
1790 dataerrln("File %s, line %d, failed with status = %s", __FILE__
, __LINE__
, u_errorName(status
));
1791 goto end_basic_tz_test
;
1794 // delete the source time zone, to make sure there are no dependencies on it.
1797 // Create another simple time zone w the same rules, and check that it is the
1798 // same as the test VTimeZone created above.
1800 SimpleTimeZone
simpleTZ2(28800000, "Asia/Singapore");
1801 simpleTZ2
.setStartYear(1970);
1802 simpleTZ2
.setStartRule(0, // month
1806 simpleTZ2
.setEndRule(1, 1, 0, status
);
1807 if (U_FAILURE(status
)) {
1808 errln("File %s, line %d, failed with status = %s", __FILE__
, __LINE__
, u_errorName(status
));
1809 goto end_basic_tz_test
;
1811 if (vtzFromBasic
->hasSameRules(simpleTZ2
) == FALSE
) {
1812 errln("File %s, line %d, failed hasSameRules() ", __FILE__
, __LINE__
);
1813 goto end_basic_tz_test
;
1817 delete vtzFromBasic
;
1827 TimeZoneRuleTest::TestVTimeZoneParse(void) {
1828 UErrorCode status
= U_ZERO_ERROR
;
1830 // Trying to create VTimeZone from empty data
1831 UnicodeString emptyData
;
1832 VTimeZone
*empty
= VTimeZone::createVTimeZone(emptyData
, status
);
1833 if (U_SUCCESS(status
) || empty
!= NULL
) {
1835 errln("FAIL: Non-null VTimeZone is returned for empty VTIMEZONE data");
1837 status
= U_ZERO_ERROR
;
1839 // Create VTimeZone for Asia/Tokyo
1840 UnicodeString
asiaTokyoID("Asia/Tokyo");
1841 static const UChar asiaTokyo
[] = {
1842 /* "BEGIN:VTIMEZONE\x0D\x0A" */
1843 0x42,0x45,0x47,0x49,0x4E,0x3A,0x56,0x54,0x49,0x4D,0x45,0x5A,0x4F,0x4E,0x45,0x0D,0x0A,
1844 /* "TZID:Asia\x0D\x0A" */
1845 0x54,0x5A,0x49,0x44,0x3A,0x41,0x73,0x69,0x61,0x0D,0x0A,
1846 /* "\x09/Tokyo\x0D\x0A" */
1847 0x09,0x2F,0x54,0x6F,0x6B,0x79,0x6F,0x0D,0x0A,
1848 /* "BEGIN:STANDARD\x0D\x0A" */
1849 0x42,0x45,0x47,0x49,0x4E,0x3A,0x53,0x54,0x41,0x4E,0x44,0x41,0x52,0x44,0x0D,0x0A,
1850 /* "TZOFFSETFROM:+0900\x0D\x0A" */
1851 0x54,0x5A,0x4F,0x46,0x46,0x53,0x45,0x54,0x46,0x52,0x4F,0x4D,0x3A,0x2B,0x30,0x39,0x30,0x30,0x0D,0x0A,
1852 /* "TZOFFSETTO:+0900\x0D\x0A" */
1853 0x54,0x5A,0x4F,0x46,0x46,0x53,0x45,0x54,0x54,0x4F,0x3A,0x2B,0x30,0x39,0x30,0x30,0x0D,0x0A,
1854 /* "TZNAME:JST\x0D\x0A" */
1855 0x54,0x5A,0x4E,0x41,0x4D,0x45,0x3A,0x4A,0x53,0x54,0x0D,0x0A,
1856 /* "DTSTART:19700101\x0D\x0A" */
1857 0x44,0x54,0x53,0x54,0x41,0x52,0x54,0x3A,0x31,0x39,0x37,0x30,0x30,0x31,0x30,0x31,0x0D,0x0A,
1858 /* " T000000\x0D\x0A" */
1859 0x20,0x54,0x30,0x30,0x30,0x30,0x30,0x30,0x0D,0x0A,
1860 /* "END:STANDARD\x0D\x0A" */
1861 0x45,0x4E,0x44,0x3A,0x53,0x54,0x41,0x4E,0x44,0x41,0x52,0x44,0x0D,0x0A,
1862 /* "END:VTIMEZONE" */
1863 0x45,0x4E,0x44,0x3A,0x56,0x54,0x49,0x4D,0x45,0x5A,0x4F,0x4E,0x45,
1866 VTimeZone
*tokyo
= VTimeZone::createVTimeZone(asiaTokyo
, status
);
1867 if (U_FAILURE(status
) || tokyo
== NULL
) {
1868 errln("FAIL: Failed to create a VTimeZone tokyo");
1873 if (tzid
!= asiaTokyoID
) {
1874 errln((UnicodeString
)"FAIL: Invalid TZID: " + tzid
);
1876 // Make sure offsets are correct
1877 int32_t rawOffset
, dstSavings
;
1878 tokyo
->getOffset(Calendar::getNow(), FALSE
, rawOffset
, dstSavings
, status
);
1879 if (U_FAILURE(status
)) {
1880 errln("FAIL: getOffset failed for tokyo");
1882 if (rawOffset
!= 9*HOUR
|| dstSavings
!= 0) {
1883 errln("FAIL: Bad offsets returned by a VTimeZone created for Tokyo");
1888 // Create VTimeZone from VTIMEZONE data
1889 static const UChar fooData
[] = {
1890 /* "BEGIN:VCALENDAR\x0D\x0A" */
1891 0x42,0x45,0x47,0x49,0x4E,0x3A,0x56,0x43,0x41,0x4C,0x45,0x4E,0x44,0x41,0x52,0x0D,0x0A,
1892 /* "BEGIN:VTIMEZONE\x0D\x0A" */
1893 0x42,0x45,0x47,0x49,0x4E,0x3A,0x56,0x54,0x49,0x4D,0x45,0x5A,0x4F,0x4E,0x45,0x0D,0x0A,
1894 /* "TZID:FOO\x0D\x0A" */
1895 0x54,0x5A,0x49,0x44,0x3A,0x46,0x4F,0x4F,0x0D,0x0A,
1896 /* "BEGIN:STANDARD\x0D\x0A" */
1897 0x42,0x45,0x47,0x49,0x4E,0x3A,0x53,0x54,0x41,0x4E,0x44,0x41,0x52,0x44,0x0D,0x0A,
1898 /* "TZOFFSETFROM:-0700\x0D\x0A" */
1899 0x54,0x5A,0x4F,0x46,0x46,0x53,0x45,0x54,0x46,0x52,0x4F,0x4D,0x3A,0x2D,0x30,0x37,0x30,0x30,0x0D,0x0A,
1900 /* "TZOFFSETTO:-0800\x0D\x0A" */
1901 0x54,0x5A,0x4F,0x46,0x46,0x53,0x45,0x54,0x54,0x4F,0x3A,0x2D,0x30,0x38,0x30,0x30,0x0D,0x0A,
1902 /* "TZNAME:FST\x0D\x0A" */
1903 0x54,0x5A,0x4E,0x41,0x4D,0x45,0x3A,0x46,0x53,0x54,0x0D,0x0A,
1904 /* "DTSTART:20071010T010000\x0D\x0A" */
1905 0x44,0x54,0x53,0x54,0x41,0x52,0x54,0x3A,0x32,0x30,0x30,0x37,0x31,0x30,0x31,0x30,0x54,0x30,0x31,0x30,0x30,0x30,0x30,0x0D,0x0A,
1906 /* "RRULE:FREQ=YEARLY;BYDAY=WE;BYMONTHDAY=10,11,12,13,14,15,16;BYMONTH=10\x0D\x0A" */
1907 0x52,0x52,0x55,0x4C,0x45,0x3A,0x46,0x52,0x45,0x51,0x3D,0x59,0x45,0x41,0x52,0x4C,0x59,0x3B,0x42,0x59,0x44,0x41,0x59,0x3D,0x57,0x45,0x3B,0x42,0x59,0x4D,0x4F,0x4E,0x54,0x48,0x44,0x41,0x59,0x3D,0x31,0x30,0x2C,0x31,0x31,0x2C,0x31,0x32,0x2C,0x31,0x33,0x2C,0x31,0x34,0x2C,0x31,0x35,0x2C,0x31,0x36,0x3B,0x42,0x59,0x4D,0x4F,0x4E,0x54,0x48,0x3D,0x31,0x30,0x0D,0x0A,
1908 /* "END:STANDARD\x0D\x0A" */
1909 0x45,0x4E,0x44,0x3A,0x53,0x54,0x41,0x4E,0x44,0x41,0x52,0x44,0x0D,0x0A,
1910 /* "BEGIN:DAYLIGHT\x0D\x0A" */
1911 0x42,0x45,0x47,0x49,0x4E,0x3A,0x44,0x41,0x59,0x4C,0x49,0x47,0x48,0x54,0x0D,0x0A,
1912 /* "TZOFFSETFROM:-0800\x0D\x0A" */
1913 0x54,0x5A,0x4F,0x46,0x46,0x53,0x45,0x54,0x46,0x52,0x4F,0x4D,0x3A,0x2D,0x30,0x38,0x30,0x30,0x0D,0x0A,
1914 /* "TZOFFSETTO:-0700\x0D\x0A" */
1915 0x54,0x5A,0x4F,0x46,0x46,0x53,0x45,0x54,0x54,0x4F,0x3A,0x2D,0x30,0x37,0x30,0x30,0x0D,0x0A,
1916 /* "TZNAME:FDT\x0D\x0A" */
1917 0x54,0x5A,0x4E,0x41,0x4D,0x45,0x3A,0x46,0x44,0x54,0x0D,0x0A,
1918 /* "DTSTART:20070415T010000\x0D\x0A" */
1919 0x44,0x54,0x53,0x54,0x41,0x52,0x54,0x3A,0x32,0x30,0x30,0x37,0x30,0x34,0x31,0x35,0x54,0x30,0x31,0x30,0x30,0x30,0x30,0x0D,0x0A,
1920 /* "RRULE:FREQ=YEARLY;BYMONTHDAY=15;BYMONTH=4\x0D\x0A" */
1921 0x52,0x52,0x55,0x4C,0x45,0x3A,0x46,0x52,0x45,0x51,0x3D,0x59,0x45,0x41,0x52,0x4C,0x59,0x3B,0x42,0x59,0x4D,0x4F,0x4E,0x54,0x48,0x44,0x41,0x59,0x3D,0x31,0x35,0x3B,0x42,0x59,0x4D,0x4F,0x4E,0x54,0x48,0x3D,0x34,0x0D,0x0A,
1922 /* "END:DAYLIGHT\x0D\x0A" */
1923 0x45,0x4E,0x44,0x3A,0x44,0x41,0x59,0x4C,0x49,0x47,0x48,0x54,0x0D,0x0A,
1924 /* "END:VTIMEZONE\x0D\x0A" */
1925 0x45,0x4E,0x44,0x3A,0x56,0x54,0x49,0x4D,0x45,0x5A,0x4F,0x4E,0x45,0x0D,0x0A,
1926 /* "END:VCALENDAR" */
1927 0x45,0x4E,0x44,0x3A,0x56,0x43,0x41,0x4C,0x45,0x4E,0x44,0x41,0x52,
1931 VTimeZone
*foo
= VTimeZone::createVTimeZone(fooData
, status
);
1932 if (U_FAILURE(status
) || foo
== NULL
) {
1933 errln("FAIL: Failed to create a VTimeZone foo");
1935 // Write VTIMEZONE data
1936 UnicodeString fooData2
;
1937 foo
->write(getUTCMillis(2005, UCAL_JANUARY
, 1), fooData2
, status
);
1938 if (U_FAILURE(status
)) {
1939 errln("FAIL: Failed to write VTIMEZONE data for foo");
1947 TimeZoneRuleTest::TestT6216(void) {
1948 // Test case in #6216
1949 static const UChar tokyoTZ
[] = {
1950 /* "BEGIN:VCALENDAR\r\n" */
1951 0x42,0x45,0x47,0x49,0x4e,0x3a,0x56,0x43,0x41,0x4c,0x45,0x4e,0x44,0x41,0x52,0x0d,0x0a,
1952 /* "VERSION:2.0\r\n" */
1953 0x56,0x45,0x52,0x53,0x49,0x4f,0x4e,0x3a,0x32,0x2e,0x30,0x0d,0x0a,
1954 /* "PRODID:-//PYVOBJECT//NONSGML Version 1//EN\r\n" */
1955 0x50,0x52,0x4f,0x44,0x49,0x44,0x3a,0x2d,0x2f,0x2f,0x50,0x59,0x56,0x4f,0x42,0x4a,0x45,0x43,0x54,0x2f,0x2f,0x4e,0x4f,0x4e,0x53,0x47,0x4d,0x4c,0x20,0x56,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x31,0x2f,0x2f,0x45,0x4e,0x0d,0x0a,
1956 /* "BEGIN:VTIMEZONE\r\n" */
1957 0x42,0x45,0x47,0x49,0x4e,0x3a,0x56,0x54,0x49,0x4d,0x45,0x5a,0x4f,0x4e,0x45,0x0d,0x0a,
1958 /* "TZID:Asia/Tokyo\r\n" */
1959 0x54,0x5a,0x49,0x44,0x3a,0x41,0x73,0x69,0x61,0x2f,0x54,0x6f,0x6b,0x79,0x6f,0x0d,0x0a,
1960 /* "BEGIN:STANDARD\r\n" */
1961 0x42,0x45,0x47,0x49,0x4e,0x3a,0x53,0x54,0x41,0x4e,0x44,0x41,0x52,0x44,0x0d,0x0a,
1962 /* "DTSTART:20000101T000000\r\n" */
1963 0x44,0x54,0x53,0x54,0x41,0x52,0x54,0x3a,0x32,0x30,0x30,0x30,0x30,0x31,0x30,0x31,0x54,0x30,0x30,0x30,0x30,0x30,0x30,0x0d,0x0a,
1964 /* "RRULE:FREQ=YEARLY;BYMONTH=1\r\n" */
1965 0x52,0x52,0x55,0x4c,0x45,0x3a,0x46,0x52,0x45,0x51,0x3d,0x59,0x45,0x41,0x52,0x4c,0x59,0x3b,0x42,0x59,0x4d,0x4f,0x4e,0x54,0x48,0x3d,0x31,0x0d,0x0a,
1966 /* "TZNAME:Asia/Tokyo\r\n" */
1967 0x54,0x5a,0x4e,0x41,0x4d,0x45,0x3a,0x41,0x73,0x69,0x61,0x2f,0x54,0x6f,0x6b,0x79,0x6f,0x0d,0x0a,
1968 /* "TZOFFSETFROM:+0900\r\n" */
1969 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x46,0x52,0x4f,0x4d,0x3a,0x2b,0x30,0x39,0x30,0x30,0x0d,0x0a,
1970 /* "TZOFFSETTO:+0900\r\n" */
1971 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x54,0x4f,0x3a,0x2b,0x30,0x39,0x30,0x30,0x0d,0x0a,
1972 /* "END:STANDARD\r\n" */
1973 0x45,0x4e,0x44,0x3a,0x53,0x54,0x41,0x4e,0x44,0x41,0x52,0x44,0x0d,0x0a,
1974 /* "END:VTIMEZONE\r\n" */
1975 0x45,0x4e,0x44,0x3a,0x56,0x54,0x49,0x4d,0x45,0x5a,0x4f,0x4e,0x45,0x0d,0x0a,
1976 /* "END:VCALENDAR" */
1977 0x45,0x4e,0x44,0x3a,0x56,0x43,0x41,0x4c,0x45,0x4e,0x44,0x41,0x52,0x0d,0x0a,
1980 // Single final rule, overlapping with another
1981 static const UChar finalOverlap
[] = {
1982 /* "BEGIN:VCALENDAR\r\n" */
1983 0x42,0x45,0x47,0x49,0x4e,0x3a,0x56,0x43,0x41,0x4c,0x45,0x4e,0x44,0x41,0x52,0x0d,0x0a,
1984 /* "BEGIN:VTIMEZONE\r\n" */
1985 0x42,0x45,0x47,0x49,0x4e,0x3a,0x56,0x54,0x49,0x4d,0x45,0x5a,0x4f,0x4e,0x45,0x0d,0x0a,
1986 /* "TZID:FinalOverlap\r\n" */
1987 0x54,0x5a,0x49,0x44,0x3a,0x46,0x69,0x6e,0x61,0x6c,0x4f,0x76,0x65,0x72,0x6c,0x61,0x70,0x0d,0x0a,
1988 /* "BEGIN:STANDARD\r\n" */
1989 0x42,0x45,0x47,0x49,0x4e,0x3a,0x53,0x54,0x41,0x4e,0x44,0x41,0x52,0x44,0x0d,0x0a,
1990 /* "TZOFFSETFROM:-0200\r\n" */
1991 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x46,0x52,0x4f,0x4d,0x3a,0x2d,0x30,0x32,0x30,0x30,0x0d,0x0a,
1992 /* "TZOFFSETTO:-0300\r\n" */
1993 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x54,0x4f,0x3a,0x2d,0x30,0x33,0x30,0x30,0x0d,0x0a,
1994 /* "TZNAME:STD\r\n" */
1995 0x54,0x5a,0x4e,0x41,0x4d,0x45,0x3a,0x53,0x54,0x44,0x0d,0x0a,
1996 /* "DTSTART:20001029T020000\r\n" */
1997 0x44,0x54,0x53,0x54,0x41,0x52,0x54,0x3a,0x32,0x30,0x30,0x30,0x31,0x30,0x32,0x39,0x54,0x30,0x32,0x30,0x30,0x30,0x30,0x0d,0x0a,
1998 /* "RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10\r\n" */
1999 0x52,0x52,0x55,0x4c,0x45,0x3a,0x46,0x52,0x45,0x51,0x3d,0x59,0x45,0x41,0x52,0x4c,0x59,0x3b,0x42,0x59,0x44,0x41,0x59,0x3d,0x2d,0x31,0x53,0x55,0x3b,0x42,0x59,0x4d,0x4f,0x4e,0x54,0x48,0x3d,0x31,0x30,0x0d,0x0a,
2000 /* "END:STANDARD\r\n" */
2001 0x45,0x4e,0x44,0x3a,0x53,0x54,0x41,0x4e,0x44,0x41,0x52,0x44,0x0d,0x0a,
2002 /* "BEGIN:DAYLIGHT\r\n" */
2003 0x42,0x45,0x47,0x49,0x4e,0x3a,0x44,0x41,0x59,0x4c,0x49,0x47,0x48,0x54,0x0d,0x0a,
2004 /* "TZOFFSETFROM:-0300\r\n" */
2005 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x46,0x52,0x4f,0x4d,0x3a,0x2d,0x30,0x33,0x30,0x30,0x0d,0x0a,
2006 /* "TZOFFSETTO:-0200\r\n" */
2007 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x54,0x4f,0x3a,0x2d,0x30,0x32,0x30,0x30,0x0d,0x0a,
2008 /* "TZNAME:DST\r\n" */
2009 0x54,0x5a,0x4e,0x41,0x4d,0x45,0x3a,0x44,0x53,0x54,0x0d,0x0a,
2010 /* "DTSTART:19990404T020000\r\n" */
2011 0x44,0x54,0x53,0x54,0x41,0x52,0x54,0x3a,0x31,0x39,0x39,0x39,0x30,0x34,0x30,0x34,0x54,0x30,0x32,0x30,0x30,0x30,0x30,0x0d,0x0a,
2012 /* "RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4;UNTIL=20050403T040000Z\r\n" */
2013 0x52,0x52,0x55,0x4c,0x45,0x3a,0x46,0x52,0x45,0x51,0x3d,0x59,0x45,0x41,0x52,0x4c,0x59,0x3b,0x42,0x59,0x44,0x41,0x59,0x3d,0x31,0x53,0x55,0x3b,0x42,0x59,0x4d,0x4f,0x4e,0x54,0x48,0x3d,0x34,0x3b,0x55,0x4e,0x54,0x49,0x4c,0x3d,0x32,0x30,0x30,0x35,0x30,0x34,0x30,0x33,0x54,0x30,0x34,0x30,0x30,0x30,0x30,0x5a,0x0d,0x0a,
2014 /* "END:DAYLIGHT\r\n" */
2015 0x45,0x4e,0x44,0x3a,0x44,0x41,0x59,0x4c,0x49,0x47,0x48,0x54,0x0d,0x0a,
2016 /* "END:VTIMEZONE\r\n" */
2017 0x45,0x4e,0x44,0x3a,0x56,0x54,0x49,0x4d,0x45,0x5a,0x4f,0x4e,0x45,0x0d,0x0a,
2018 /* "END:VCALENDAR" */
2019 0x45,0x4e,0x44,0x3a,0x56,0x43,0x41,0x4c,0x45,0x4e,0x44,0x41,0x52,0x0d,0x0a,
2022 // Single final rule, no overlapping with another
2023 static const UChar finalNonOverlap
[] = {
2024 /* "BEGIN:VCALENDAR\r\n" */
2025 0x42,0x45,0x47,0x49,0x4e,0x3a,0x56,0x43,0x41,0x4c,0x45,0x4e,0x44,0x41,0x52,0x0d,0x0a,
2026 /* "BEGIN:VTIMEZONE\r\n" */
2027 0x42,0x45,0x47,0x49,0x4e,0x3a,0x56,0x54,0x49,0x4d,0x45,0x5a,0x4f,0x4e,0x45,0x0d,0x0a,
2028 /* "TZID:FinalNonOverlap\r\n" */
2029 0x54,0x5a,0x49,0x44,0x3a,0x46,0x69,0x6e,0x61,0x6c,0x4e,0x6f,0x6e,0x4f,0x76,0x65,0x72,0x6c,0x61,0x70,0x0d,0x0a,
2030 /* "BEGIN:STANDARD\r\n" */
2031 0x42,0x45,0x47,0x49,0x4e,0x3a,0x53,0x54,0x41,0x4e,0x44,0x41,0x52,0x44,0x0d,0x0a,
2032 /* "TZOFFSETFROM:-0200\r\n" */
2033 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x46,0x52,0x4f,0x4d,0x3a,0x2d,0x30,0x32,0x30,0x30,0x0d,0x0a,
2034 /* "TZOFFSETTO:-0300\r\n" */
2035 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x54,0x4f,0x3a,0x2d,0x30,0x33,0x30,0x30,0x0d,0x0a,
2036 /* "TZNAME:STD\r\n" */
2037 0x54,0x5a,0x4e,0x41,0x4d,0x45,0x3a,0x53,0x54,0x44,0x0d,0x0a,
2038 /* "DTSTART:20001029T020000\r\n" */
2039 0x44,0x54,0x53,0x54,0x41,0x52,0x54,0x3a,0x32,0x30,0x30,0x30,0x31,0x30,0x32,0x39,0x54,0x30,0x32,0x30,0x30,0x30,0x30,0x0d,0x0a,
2040 /* "RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10;UNTIL=20041031T040000Z\r\n" */
2041 0x52,0x52,0x55,0x4c,0x45,0x3a,0x46,0x52,0x45,0x51,0x3d,0x59,0x45,0x41,0x52,0x4c,0x59,0x3b,0x42,0x59,0x44,0x41,0x59,0x3d,0x2d,0x31,0x53,0x55,0x3b,0x42,0x59,0x4d,0x4f,0x4e,0x54,0x48,0x3d,0x31,0x30,0x3b,0x55,0x4e,0x54,0x49,0x4c,0x3d,0x32,0x30,0x30,0x34,0x31,0x30,0x33,0x31,0x54,0x30,0x34,0x30,0x30,0x30,0x30,0x5a,0x0d,0x0a,
2042 /* "END:STANDARD\r\n" */
2043 0x45,0x4e,0x44,0x3a,0x53,0x54,0x41,0x4e,0x44,0x41,0x52,0x44,0x0d,0x0a,
2044 /* "BEGIN:DAYLIGHT\r\n" */
2045 0x42,0x45,0x47,0x49,0x4e,0x3a,0x44,0x41,0x59,0x4c,0x49,0x47,0x48,0x54,0x0d,0x0a,
2046 /* "TZOFFSETFROM:-0300\r\n" */
2047 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x46,0x52,0x4f,0x4d,0x3a,0x2d,0x30,0x33,0x30,0x30,0x0d,0x0a,
2048 /* "TZOFFSETTO:-0200\r\n" */
2049 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x54,0x4f,0x3a,0x2d,0x30,0x32,0x30,0x30,0x0d,0x0a,
2050 /* "TZNAME:DST\r\n" */
2051 0x54,0x5a,0x4e,0x41,0x4d,0x45,0x3a,0x44,0x53,0x54,0x0d,0x0a,
2052 /* "DTSTART:19990404T020000\r\n" */
2053 0x44,0x54,0x53,0x54,0x41,0x52,0x54,0x3a,0x31,0x39,0x39,0x39,0x30,0x34,0x30,0x34,0x54,0x30,0x32,0x30,0x30,0x30,0x30,0x0d,0x0a,
2054 /* "RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4;UNTIL=20050403T040000Z\r\n" */
2055 0x52,0x52,0x55,0x4c,0x45,0x3a,0x46,0x52,0x45,0x51,0x3d,0x59,0x45,0x41,0x52,0x4c,0x59,0x3b,0x42,0x59,0x44,0x41,0x59,0x3d,0x31,0x53,0x55,0x3b,0x42,0x59,0x4d,0x4f,0x4e,0x54,0x48,0x3d,0x34,0x3b,0x55,0x4e,0x54,0x49,0x4c,0x3d,0x32,0x30,0x30,0x35,0x30,0x34,0x30,0x33,0x54,0x30,0x34,0x30,0x30,0x30,0x30,0x5a,0x0d,0x0a,
2056 /* "END:DAYLIGHT\r\n" */
2057 0x45,0x4e,0x44,0x3a,0x44,0x41,0x59,0x4c,0x49,0x47,0x48,0x54,0x0d,0x0a,
2058 /* "BEGIN:STANDARD\r\n" */
2059 0x42,0x45,0x47,0x49,0x4e,0x3a,0x53,0x54,0x41,0x4e,0x44,0x41,0x52,0x44,0x0d,0x0a,
2060 /* "TZOFFSETFROM:-0200\r\n" */
2061 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x46,0x52,0x4f,0x4d,0x3a,0x2d,0x30,0x32,0x30,0x30,0x0d,0x0a,
2062 /* "TZOFFSETTO:-0300\r\n" */
2063 0x54,0x5a,0x4f,0x46,0x46,0x53,0x45,0x54,0x54,0x4f,0x3a,0x2d,0x30,0x33,0x30,0x30,0x0d,0x0a,
2064 /* "TZNAME:STDFINAL\r\n" */
2065 0x54,0x5a,0x4e,0x41,0x4d,0x45,0x3a,0x53,0x54,0x44,0x46,0x49,0x4e,0x41,0x4c,0x0d,0x0a,
2066 /* "DTSTART:20071028T020000\r\n" */
2067 0x44,0x54,0x53,0x54,0x41,0x52,0x54,0x3a,0x32,0x30,0x30,0x37,0x31,0x30,0x32,0x38,0x54,0x30,0x32,0x30,0x30,0x30,0x30,0x0d,0x0a,
2068 /* "RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10\r\n" */
2069 0x52,0x52,0x55,0x4c,0x45,0x3a,0x46,0x52,0x45,0x51,0x3d,0x59,0x45,0x41,0x52,0x4c,0x59,0x3b,0x42,0x59,0x44,0x41,0x59,0x3d,0x2d,0x31,0x53,0x55,0x3b,0x42,0x59,0x4d,0x4f,0x4e,0x54,0x48,0x3d,0x31,0x30,0x0d,0x0a,
2070 /* "END:STANDARD\r\n" */
2071 0x45,0x4e,0x44,0x3a,0x53,0x54,0x41,0x4e,0x44,0x41,0x52,0x44,0x0d,0x0a,
2072 /* "END:VTIMEZONE\r\n" */
2073 0x45,0x4e,0x44,0x3a,0x56,0x54,0x49,0x4d,0x45,0x5a,0x4f,0x4e,0x45,0x0d,0x0a,
2074 /* "END:VCALENDAR" */
2075 0x45,0x4e,0x44,0x3a,0x56,0x43,0x41,0x4c,0x45,0x4e,0x44,0x41,0x52,0x0d,0x0a,
2079 static const int32_t TestDates
[][3] = {
2080 {1995, UCAL_JANUARY
, 1},
2081 {1995, UCAL_JULY
, 1},
2082 {2000, UCAL_JANUARY
, 1},
2083 {2000, UCAL_JULY
, 1},
2084 {2005, UCAL_JANUARY
, 1},
2085 {2005, UCAL_JULY
, 1},
2086 {2010, UCAL_JANUARY
, 1},
2087 {2010, UCAL_JULY
, 1},
2091 /*static*/ const UnicodeString TestZones
[] = {
2092 UnicodeString(tokyoTZ
),
2093 UnicodeString(finalOverlap
),
2094 UnicodeString(finalNonOverlap
),
2098 int32_t Expected
[][8] = {
2099 // JAN90 JUL90 JAN00 JUL00 JAN05 JUL05 JAN10 JUL10
2100 { 32400000, 32400000, 32400000, 32400000, 32400000, 32400000, 32400000, 32400000},
2101 {-10800000, -10800000, -7200000, -7200000, -10800000, -7200000, -10800000, -10800000},
2102 {-10800000, -10800000, -7200000, -7200000, -10800000, -7200000, -10800000, -10800000}
2108 UDate times
[sizeof(TestDates
) / (3 * sizeof(int32_t))];
2111 UErrorCode status
= U_ZERO_ERROR
;
2112 TimeZone
*utc
= TimeZone::createTimeZone("Etc/GMT");
2113 GregorianCalendar
cal(utc
, status
);
2114 if (U_FAILURE(status
)) {
2115 dataerrln("FAIL: Failed to creat a GregorianCalendar: %s", u_errorName(status
));
2118 for (i
= 0; TestDates
[i
][2] != 0; i
++) {
2120 cal
.set(TestDates
[i
][0], TestDates
[i
][1], TestDates
[i
][2]);
2121 times
[i
] = cal
.getTime(status
);
2122 if (U_FAILURE(status
)) {
2123 errln("FAIL: getTime failed");
2130 for (i
= 0; !TestZones
[i
].isEmpty(); i
++) {
2131 VTimeZone
*vtz
= VTimeZone::createVTimeZone(TestZones
[i
], status
);
2132 if (U_FAILURE(status
)) {
2133 errln("FAIL: failed to create VTimeZone");
2136 for (j
= 0; j
< numTimes
; j
++) {
2138 status
= U_ZERO_ERROR
;
2139 vtz
->getOffset(times
[j
], FALSE
, raw
, dst
, status
);
2140 if (U_FAILURE(status
)) {
2141 errln((UnicodeString
)"FAIL: getOffset failed for time zone " + i
+ " at " + times
[j
]);
2143 int32_t offset
= raw
+ dst
;
2144 if (offset
!= Expected
[i
][j
]) {
2145 errln((UnicodeString
)"FAIL: Invalid offset at time(" + times
[j
] + "):" + offset
+ " Expected:" + Expected
[i
][j
]);
2153 TimeZoneRuleTest::TestT6669(void) {
2154 UErrorCode status
= U_ZERO_ERROR
;
2155 SimpleTimeZone
stz(0, "CustomID", UCAL_JANUARY
, 1, UCAL_SUNDAY
, 0, UCAL_JULY
, 1, UCAL_SUNDAY
, 0, status
);
2156 if (U_FAILURE(status
)) {
2157 errln("FAIL: Failed to creat a SimpleTimeZone");
2161 UDate t
= 1230681600000.0; //2008-12-31T00:00:00
2162 UDate expectedNext
= 1231027200000.0; //2009-01-04T00:00:00
2163 UDate expectedPrev
= 1215298800000.0; //2008-07-06T00:00:00
2165 TimeZoneTransition tzt
;
2166 UBool avail
= stz
.getNextTransition(t
, FALSE
, tzt
);
2168 errln("FAIL: No transition returned by getNextTransition.");
2169 } else if (tzt
.getTime() != expectedNext
) {
2170 errln((UnicodeString
)"FAIL: Wrong transition time returned by getNextTransition - "
2171 + tzt
.getTime() + " Expected: " + expectedNext
);
2174 avail
= stz
.getPreviousTransition(t
, TRUE
, tzt
);
2176 errln("FAIL: No transition returned by getPreviousTransition.");
2177 } else if (tzt
.getTime() != expectedPrev
) {
2178 errln((UnicodeString
)"FAIL: Wrong transition time returned by getPreviousTransition - "
2179 + tzt
.getTime() + " Expected: " + expectedPrev
);
2184 TimeZoneRuleTest::TestVTimeZoneWrapper(void) {
2188 UChar
* data
= NULL
;
2192 UDate base
= 1231027200000.0; //2009-01-04T00:00:00
2195 const char *name
= "Test Initial";
2209 uprv_memset(uname
, 0, sizeof(uname
));
2210 u_uastrcpy(uname
, name
);
2213 ir1
= izrule_open(uname
, 13, 2*HOUR
, 0);
2214 ir2
= izrule_clone(ir1
);
2217 b
= izrule_equals(ir1
, ir2
);
2218 b
= izrule_isEquivalentTo(ir1
, ir2
);
2221 izrule_getName(ir1
, data
, length
);
2222 i
= izrule_getRawOffset(ir1
);
2223 i
= izrule_getDSTSavings(ir1
);
2225 b
= izrule_getFirstStart(ir1
, 2*HOUR
, 0, result
);
2226 b
= izrule_getFinalStart(ir1
, 2*HOUR
, 0, result
);
2227 b
= izrule_getNextStart(ir1
, base
, 2*HOUR
, 0, true, result
);
2228 b
= izrule_getPreviousStart(ir1
, base
, 2*HOUR
, 0, true, result
);
2231 cid1
= izrule_getStaticClassID(ir1
);
2232 cid2
= izrule_getDynamicClassID(ir1
);
2235 zt1
= ztrans_open(base
, ir1
, ir2
);
2236 zt2
= ztrans_clone(zt1
);
2237 zt2
= ztrans_openEmpty();
2240 b
= ztrans_equals(zt1
, zt2
);
2243 result
= ztrans_getTime(zt1
);
2244 ztrans_setTime(zt1
, result
);
2246 r
= (ZRule
*)ztrans_getFrom(zt1
);
2247 ztrans_setFrom(zt1
, (void*)ir1
);
2248 ztrans_adoptFrom(zt1
, (void*)ir1
);
2250 r
= (ZRule
*)ztrans_getTo(zt1
);
2251 ztrans_setTo(zt1
, (void*)ir2
);
2252 ztrans_adoptTo(zt1
, (void*)ir2
);
2255 cid1
= ztrans_getStaticClassID(zt1
);
2256 cid2
= ztrans_getDynamicClassID(zt2
);
2259 v1
= vzone_openID((UChar
*)"America/Chicago", sizeof("America/Chicago"));
2260 v2
= vzone_clone(v1
);
2261 //v2 = vzone_openData(const UChar* vtzdata, int32_t vtzdataLength, UErrorCode& status);
2264 b
= vzone_equals(v1
, v2
);
2265 b
= vzone_hasSameRules(v1
, v2
);
2268 b
= vzone_getTZURL(v1
, data
, length
);
2269 vzone_setTZURL(v1
, data
, length
);
2271 b
= vzone_getLastModified(v1
, result
);
2272 vzone_setLastModified(v1
, result
);
2275 vzone_write(v1
, data
, length
, status
);
2276 vzone_writeFromStart(v1
, result
, data
, length
, status
);
2277 vzone_writeSimple(v1
, result
, data
, length
, status
);
2279 // test more accessors
2280 i
= vzone_getRawOffset(v1
);
2281 vzone_setRawOffset(v1
, i
);
2283 b
= vzone_useDaylightTime(v1
);
2284 b
= vzone_inDaylightTime(v1
, result
, status
);
2286 b
= vzone_getNextTransition(v1
, result
, false, zt1
);
2287 b
= vzone_getPreviousTransition(v1
, result
, false, zt1
);
2288 i
= vzone_countTransitionRules(v1
, status
);
2290 cid1
= vzone_getStaticClassID(v1
);
2291 cid2
= vzone_getDynamicClassID(v1
);
2301 //----------- private test helpers -------------------------------------------------
2304 TimeZoneRuleTest::getUTCMillis(int32_t y
, int32_t m
, int32_t d
,
2305 int32_t hr
, int32_t min
, int32_t sec
, int32_t msec
) {
2306 UErrorCode status
= U_ZERO_ERROR
;
2307 const TimeZone
*tz
= TimeZone::getGMT();
2308 Calendar
*cal
= Calendar::createInstance(*tz
, status
);
2309 if (U_FAILURE(status
)) {
2311 dataerrln("FAIL: Calendar::createInstance failed: %s", u_errorName(status
));
2314 cal
->set(y
, m
, d
, hr
, min
, sec
);
2315 cal
->set(UCAL_MILLISECOND
, msec
);
2316 UDate utc
= cal
->getTime(status
);
2317 if (U_FAILURE(status
)) {
2319 errln("FAIL: Calendar::getTime failed");
2327 * Check if a time shift really happens on each transition returned by getNextTransition or
2328 * getPreviousTransition in the specified time range
2331 TimeZoneRuleTest::verifyTransitions(BasicTimeZone
& icutz
, UDate start
, UDate end
) {
2332 UErrorCode status
= U_ZERO_ERROR
;
2334 int32_t raw
, dst
, raw0
, dst0
;
2335 TimeZoneTransition tzt
, tzt0
;
2343 avail
= icutz
.getNextTransition(time
, FALSE
, tzt
);
2347 time
= tzt
.getTime();
2351 icutz
.getOffset(time
, FALSE
, raw
, dst
, status
);
2352 icutz
.getOffset(time
- 1, FALSE
, raw0
, dst0
, status
);
2353 if (U_FAILURE(status
)) {
2354 errln("FAIL: Error in getOffset");
2358 if (raw
== raw0
&& dst
== dst0
) {
2359 errln((UnicodeString
)"FAIL: False transition returned by getNextTransition for "
2360 + icutz
.getID(tzid
) + " at " + dateToString(time
));
2363 (tzt0
.getTo()->getRawOffset() != tzt
.getFrom()->getRawOffset()
2364 || tzt0
.getTo()->getDSTSavings() != tzt
.getFrom()->getDSTSavings())) {
2365 errln((UnicodeString
)"FAIL: TO rule of the previous transition does not match FROM rule of this transtion at "
2366 + dateToString(time
) + " for " + icutz
.getID(tzid
));
2376 avail
= icutz
.getPreviousTransition(time
, FALSE
, tzt
);
2380 time
= tzt
.getTime();
2381 if (time
<= start
) {
2384 icutz
.getOffset(time
, FALSE
, raw
, dst
, status
);
2385 icutz
.getOffset(time
- 1, FALSE
, raw0
, dst0
, status
);
2386 if (U_FAILURE(status
)) {
2387 errln("FAIL: Error in getOffset");
2391 if (raw
== raw0
&& dst
== dst0
) {
2392 errln((UnicodeString
)"FAIL: False transition returned by getPreviousTransition for "
2393 + icutz
.getID(tzid
) + " at " + dateToString(time
));
2397 (tzt0
.getFrom()->getRawOffset() != tzt
.getTo()->getRawOffset()
2398 || tzt0
.getFrom()->getDSTSavings() != tzt
.getTo()->getDSTSavings())) {
2399 errln((UnicodeString
)"FAIL: TO rule of the next transition does not match FROM rule in this transtion at "
2400 + dateToString(time
) + " for " + icutz
.getID(tzid
));
2408 * Compare all time transitions in 2 time zones in the specified time range in ascending order
2411 TimeZoneRuleTest::compareTransitionsAscending(BasicTimeZone
& z1
, BasicTimeZone
& z2
,
2412 UDate start
, UDate end
, UBool inclusive
) {
2413 UnicodeString zid1
, zid2
;
2414 TimeZoneTransition tzt1
, tzt2
;
2415 UBool avail1
, avail2
;
2416 UBool inRange1
, inRange2
;
2423 avail1
= z1
.getNextTransition(time
, inclusive
, tzt1
);
2424 avail2
= z2
.getNextTransition(time
, inclusive
, tzt2
);
2426 inRange1
= inRange2
= FALSE
;
2428 if (tzt1
.getTime() < end
|| (inclusive
&& tzt1
.getTime() == end
)) {
2433 if (tzt2
.getTime() < end
|| (inclusive
&& tzt2
.getTime() == end
)) {
2437 if (!inRange1
&& !inRange2
) {
2438 // No more transition in the range
2442 errln((UnicodeString
)"FAIL: " + zid1
+ " does not have any transitions after "
2443 + dateToString(time
) + " before " + dateToString(end
));
2447 errln((UnicodeString
)"FAIL: " + zid2
+ " does not have any transitions after "
2448 + dateToString(time
) + " before " + dateToString(end
));
2451 if (tzt1
.getTime() != tzt2
.getTime()) {
2452 errln((UnicodeString
)"FAIL: First transition after " + dateToString(time
) + " "
2453 + zid1
+ "[" + dateToString(tzt1
.getTime()) + "] "
2454 + zid2
+ "[" + dateToString(tzt2
.getTime()) + "]");
2457 time
= tzt1
.getTime();
2465 * Compare all time transitions in 2 time zones in the specified time range in descending order
2468 TimeZoneRuleTest::compareTransitionsDescending(BasicTimeZone
& z1
, BasicTimeZone
& z2
,
2469 UDate start
, UDate end
, UBool inclusive
) {
2470 UnicodeString zid1
, zid2
;
2471 TimeZoneTransition tzt1
, tzt2
;
2472 UBool avail1
, avail2
;
2473 UBool inRange1
, inRange2
;
2480 avail1
= z1
.getPreviousTransition(time
, inclusive
, tzt1
);
2481 avail2
= z2
.getPreviousTransition(time
, inclusive
, tzt2
);
2483 inRange1
= inRange2
= FALSE
;
2485 if (tzt1
.getTime() > start
|| (inclusive
&& tzt1
.getTime() == start
)) {
2490 if (tzt2
.getTime() > start
|| (inclusive
&& tzt2
.getTime() == start
)) {
2494 if (!inRange1
&& !inRange2
) {
2495 // No more transition in the range
2499 errln((UnicodeString
)"FAIL: " + zid1
+ " does not have any transitions before "
2500 + dateToString(time
) + " after " + dateToString(start
));
2504 errln((UnicodeString
)"FAIL: " + zid2
+ " does not have any transitions before "
2505 + dateToString(time
) + " after " + dateToString(start
));
2508 if (tzt1
.getTime() != tzt2
.getTime()) {
2509 errln((UnicodeString
)"FAIL: Last transition before " + dateToString(time
) + " "
2510 + zid1
+ "[" + dateToString(tzt1
.getTime()) + "] "
2511 + zid2
+ "[" + dateToString(tzt2
.getTime()) + "]");
2514 time
= tzt1
.getTime();
2521 // Slightly modified version of BasicTimeZone::hasEquivalentTransitions.
2522 // This version returns TRUE if transition time delta is within the given
2524 static UBool
hasEquivalentTransitions(/*const*/ BasicTimeZone
& tz1
, /*const*/BasicTimeZone
& tz2
,
2525 UDate start
, UDate end
,
2526 UBool ignoreDstAmount
, int32_t maxTransitionTimeDelta
,
2527 UErrorCode
& status
) {
2528 if (U_FAILURE(status
)) {
2531 if (tz1
.hasSameRules(tz2
)) {
2534 // Check the offsets at the start time
2535 int32_t raw1
, raw2
, dst1
, dst2
;
2536 tz1
.getOffset(start
, FALSE
, raw1
, dst1
, status
);
2537 if (U_FAILURE(status
)) {
2540 tz2
.getOffset(start
, FALSE
, raw2
, dst2
, status
);
2541 if (U_FAILURE(status
)) {
2544 if (ignoreDstAmount
) {
2545 if ((raw1
+ dst1
!= raw2
+ dst2
)
2546 || (dst1
!= 0 && dst2
== 0)
2547 || (dst1
== 0 && dst2
!= 0)) {
2551 if (raw1
!= raw2
|| dst1
!= dst2
) {
2555 // Check transitions in the range
2557 TimeZoneTransition tr1
, tr2
;
2559 UBool avail1
= tz1
.getNextTransition(time
, FALSE
, tr1
);
2560 UBool avail2
= tz2
.getNextTransition(time
, FALSE
, tr2
);
2562 if (ignoreDstAmount
) {
2563 // Skip a transition which only differ the amount of DST savings
2566 && tr1
.getTime() <= end
2567 && (tr1
.getFrom()->getRawOffset() + tr1
.getFrom()->getDSTSavings()
2568 == tr1
.getTo()->getRawOffset() + tr1
.getTo()->getDSTSavings())
2569 && (tr1
.getFrom()->getDSTSavings() != 0 && tr1
.getTo()->getDSTSavings() != 0)) {
2570 tz1
.getNextTransition(tr1
.getTime(), FALSE
, tr1
);
2577 && tr2
.getTime() <= end
2578 && (tr2
.getFrom()->getRawOffset() + tr2
.getFrom()->getDSTSavings()
2579 == tr2
.getTo()->getRawOffset() + tr2
.getTo()->getDSTSavings())
2580 && (tr2
.getFrom()->getDSTSavings() != 0 && tr2
.getTo()->getDSTSavings() != 0)) {
2581 tz2
.getNextTransition(tr2
.getTime(), FALSE
, tr2
);
2588 UBool inRange1
= (avail1
&& tr1
.getTime() <= end
);
2589 UBool inRange2
= (avail2
&& tr2
.getTime() <= end
);
2590 if (!inRange1
&& !inRange2
) {
2591 // No more transition in the range
2594 if (!inRange1
|| !inRange2
) {
2597 double delta
= tr1
.getTime() >= tr2
.getTime() ? tr1
.getTime() - tr2
.getTime() : tr2
.getTime() - tr1
.getTime();
2598 if (delta
> (double)maxTransitionTimeDelta
) {
2601 if (ignoreDstAmount
) {
2602 if (tr1
.getTo()->getRawOffset() + tr1
.getTo()->getDSTSavings()
2603 != tr2
.getTo()->getRawOffset() + tr2
.getTo()->getDSTSavings()
2604 || (tr1
.getTo()->getDSTSavings() != 0 && tr2
.getTo()->getDSTSavings() == 0)
2605 || (tr1
.getTo()->getDSTSavings() == 0 && tr2
.getTo()->getDSTSavings() != 0)) {
2609 if (tr1
.getTo()->getRawOffset() != tr2
.getTo()->getRawOffset() ||
2610 tr1
.getTo()->getDSTSavings() != tr2
.getTo()->getDSTSavings()) {
2614 time
= tr1
.getTime() > tr2
.getTime() ? tr1
.getTime() : tr2
.getTime();
2620 #endif /* #if !UCONFIG_NO_FORMATTING */