/*
* RuleBasedTimeZone test cases
*/
public void TestSimpleRuleBasedTimeZone() {
SimpleTimeZone stz = new SimpleTimeZone(-1*HOUR, "TestSTZ",
Calendar.SEPTEMBER, -30, -Calendar.SATURDAY, 1*HOUR, SimpleTimeZone.WALL_TIME,
Calendar.FEBRUARY, 2, Calendar.SUNDAY, 1*HOUR, SimpleTimeZone.WALL_TIME,
1*HOUR);
DateTimeRule dtr;
AnnualTimeZoneRule atzr;
final int STARTYEAR = 2000;
InitialTimeZoneRule ir = new InitialTimeZoneRule(
"RBTZ_Initial", // Initial time Name
-1*HOUR, // Raw offset
1*HOUR); // DST saving amount
// RBTZ
RuleBasedTimeZone rbtz1 = new RuleBasedTimeZone("RBTZ1", ir);
dtr = new DateTimeRule(Calendar.SEPTEMBER, 30, Calendar.SATURDAY, false,
1*HOUR, DateTimeRule.WALL_TIME); // SUN<=30 in September, at 1AM wall time
atzr = new AnnualTimeZoneRule("RBTZ_DST1",
-1*HOUR /* rawOffset */, 1*HOUR /* dstSavings */, dtr,
STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
rbtz1.addTransitionRule(atzr);
dtr = new DateTimeRule(Calendar.FEBRUARY, 2, Calendar.SUNDAY,
1*HOUR, DateTimeRule.WALL_TIME); // 2nd Sunday in February, at 1AM wall time
atzr = new AnnualTimeZoneRule("RBTZ_STD1",
-1*HOUR /* rawOffset */, 0 /* dstSavings */, dtr,
STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
rbtz1.addTransitionRule(atzr);
// Equivalent, but different date rule type
RuleBasedTimeZone rbtz2 = new RuleBasedTimeZone("RBTZ2", ir);
dtr = new DateTimeRule(Calendar.SEPTEMBER, -1, Calendar.SATURDAY,
1*HOUR, DateTimeRule.WALL_TIME); // Last Sunday in September at 1AM wall time
atzr = new AnnualTimeZoneRule("RBTZ_DST2", -1*HOUR, 1*HOUR, dtr, STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
rbtz2.addTransitionRule(atzr);
dtr = new DateTimeRule(Calendar.FEBRUARY, 8, Calendar.SUNDAY, true,
1*HOUR, DateTimeRule.WALL_TIME); // SUN>=8 in February, at 1AM wall time
atzr = new AnnualTimeZoneRule("RBTZ_STD2", -1*HOUR, 0, dtr, STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
rbtz2.addTransitionRule(atzr);
// Equivalent, but different time rule type
RuleBasedTimeZone rbtz3 = new RuleBasedTimeZone("RBTZ3", ir);
dtr = new DateTimeRule(Calendar.SEPTEMBER, 30, Calendar.SATURDAY, false,
2*HOUR, DateTimeRule.UTC_TIME);
atzr = new AnnualTimeZoneRule("RBTZ_DST3", -1*HOUR, 1*HOUR, dtr, STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
rbtz3.addTransitionRule(atzr);
dtr = new DateTimeRule(Calendar.FEBRUARY, 2, Calendar.SUNDAY,
0*HOUR, DateTimeRule.STANDARD_TIME);
atzr = new AnnualTimeZoneRule("RBTZ_STD3", -1*HOUR, 0, dtr, STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
rbtz3.addTransitionRule(atzr);
// Check equivalency for 10 years
long start = getUTCMillis(STARTYEAR, Calendar.JANUARY, 1);
long until = getUTCMillis(STARTYEAR + 10, Calendar.JANUARY, 1);
if (!(stz.hasEquivalentTransitions(rbtz1, start, until))) {
errln("FAIL: rbtz1 must be equivalent to the SimpleTimeZone in the time range.");
}
if (!(stz.hasEquivalentTransitions(rbtz2, start, until))) {
errln("FAIL: rbtz2 must be equivalent to the SimpleTimeZone in the time range.");
}
if (!(stz.hasEquivalentTransitions(rbtz3, start, until))) {
errln("FAIL: rbtz3 must be equivalent to the SimpleTimeZone in the time range.");
}
// hasSameRules
if (rbtz1.hasSameRules(rbtz2)) {