DateTimeRule dtr3 = new DateTimeRule(Calendar.OCTOBER, -1, Calendar.SATURDAY,
6*HOUR, DateTimeRule.UTC_TIME); //Last Saturday in Oct, at 6 AM, UTC
DateTimeRule dtr4 = new DateTimeRule(Calendar.MARCH, 8, Calendar.SUNDAY, true,
2*HOUR, DateTimeRule.WALL_TIME); // First Sunday on or after Mar 8, at 2 AM, wall time
AnnualTimeZoneRule a1 = new AnnualTimeZoneRule("a1", -3*HOUR, 1*HOUR, dtr1,
2000, AnnualTimeZoneRule.MAX_YEAR);
AnnualTimeZoneRule a2 = new AnnualTimeZoneRule("a2", -3*HOUR, 1*HOUR, dtr1,
2000, AnnualTimeZoneRule.MAX_YEAR);
AnnualTimeZoneRule a3 = new AnnualTimeZoneRule("a3", -3*HOUR, 1*HOUR, dtr1,
2000, 2010);
InitialTimeZoneRule i1 = new InitialTimeZoneRule("i1", -3*HOUR, 0);
InitialTimeZoneRule i2 = new InitialTimeZoneRule("i2", -3*HOUR, 0);
InitialTimeZoneRule i3 = new InitialTimeZoneRule("i3", -3*HOUR, 1*HOUR);
long[] emptytimes = {};
long[] trtimes1 = {0};
long[] trtimes2 = {0, 10000000};
TimeArrayTimeZoneRule t0 = null;
try {
// Try to construct TimeArrayTimeZoneRule with null transition times
t0 = new TimeArrayTimeZoneRule("nulltimes", -3*HOUR, 0,
null, DateTimeRule.UTC_TIME);
} catch (IllegalArgumentException iae) {
logln("TimeArrayTimeZoneRule constructor throws IllegalArgumentException as expected.");
t0 = null;
}
if (t0 != null) {
errln("FAIL: TimeArrayTimeZoneRule constructor did not throw IllegalArgumentException for null times");
}
try {
// Try to construct TimeArrayTimeZoneRule with empty transition times
t0 = new TimeArrayTimeZoneRule("nulltimes", -3*HOUR, 0,
emptytimes, DateTimeRule.UTC_TIME);
} catch (IllegalArgumentException iae) {
logln("TimeArrayTimeZoneRule constructor throws IllegalArgumentException as expected.");
t0 = null;
}
if (t0 != null) {
errln("FAIL: TimeArrayTimeZoneRule constructor did not throw IllegalArgumentException for empty times");
}
TimeArrayTimeZoneRule t1 = new TimeArrayTimeZoneRule("t1", -3*HOUR, 0, trtimes1, DateTimeRule.UTC_TIME);
TimeArrayTimeZoneRule t2 = new TimeArrayTimeZoneRule("t2", -3*HOUR, 0, trtimes1, DateTimeRule.UTC_TIME);
TimeArrayTimeZoneRule t3 = new TimeArrayTimeZoneRule("t3", -3*HOUR, 0, trtimes2, DateTimeRule.UTC_TIME);
TimeArrayTimeZoneRule t4 = new TimeArrayTimeZoneRule("t4", -3*HOUR, 0, trtimes1, DateTimeRule.STANDARD_TIME);
TimeArrayTimeZoneRule t5 = new TimeArrayTimeZoneRule("t5", -4*HOUR, 1*HOUR, trtimes1, DateTimeRule.WALL_TIME);
// AnnualTimeZoneRule#getRule
if (!a1.getRule().equals(a2.getRule())) {
errln("FAIL: The same DateTimeRule must be returned from AnnualTimeZoneRule a1 and a2");
}
// AnnualTimeZoneRule#getStartYear
int startYear = a1.getStartYear();
if (startYear != 2000) {
errln("FAIL: The start year of AnnualTimeZoneRule a1 must be 2000 - returned: " + startYear);
}
// AnnualTimeZoneRule#getEndYear
int endYear = a1.getEndYear();
if (endYear != AnnualTimeZoneRule.MAX_YEAR) {
errln("FAIL: The start year of AnnualTimeZoneRule a1 must be MAX_YEAR - returned: " + endYear);
}
endYear = a3.getEndYear();
if (endYear != 2010) {
errln("FAIL: The start year of AnnualTimeZoneRule a3 must be 2010 - returned: " + endYear);
}
// AnnualTimeZone#getStartInYear
Date d1 = a1.getStartInYear(2005, -3*HOUR, 0);
Date d2 = a3.getStartInYear(2005, -3*HOUR, 0);
if (d1 == null || d2 == null || !d1.equals(d2)) {
errln("FAIL: AnnualTimeZoneRule#getStartInYear did not work as expected");
}
d2 = a3.getStartInYear(2015, -3*HOUR, 0);
if (d2 != null) {
errln("FAIL: AnnualTimeZoneRule#getSTartInYear returned non-null date for 2015 which is out of rule range");
}
// AnnualTimeZone#getFirstStart
d1 = a1.getFirstStart(-3*HOUR, 0);
d2 = a1.getFirstStart(-4*HOUR, 1*HOUR);
if (d1 == null || d2 == null || !d1.equals(d2)) {
errln("FAIL: The same start time should be returned by getFirstStart");
}
// AnnualTimeZone#getFinalStart
d1 = a1.getFinalStart(-3*HOUR, 0);
if (d1 != null) {
errln("FAIL: Non-null Date is returned by getFinalStart for a1");
}
d1 = a1.getStartInYear(2010, -3*HOUR, 0);
d2 = a3.getFinalStart(-3*HOUR, 0);
if (d1 == null || d2 == null || !d1.equals(d2)) {
errln("FAIL: Bad date is returned by getFinalStart");
}
// AnnualTimeZone#getNextStart / getPreviousStart
d1 = a1.getNextStart(time1, -3*HOUR, 0, false);
if (d1 == null) {
errln("FAIL: Null Date is returned by getNextStart");
} else {
d2 = a1.getPreviousStart(d1.getTime(), -3*HOUR, 0, true);
if (d2 == null || !d1.equals(d2)) {
errln("FAIL: Bad Date is returned by getPreviousStart");
}
}
d1 = a3.getNextStart(time2, -3*HOUR, 0, false);
if (d1 != null) {
errln("FAIL: getNextStart must return null when no start time is available after the base time");
}
d1 = a3.getFinalStart(-3*HOUR, 0);
d2 = a3.getPreviousStart(time2, -3*HOUR, 0, false);
if (d1 == null || d2 == null || !d1.equals(d2)) {
errln("FAIL: getPreviousStart does not match with getFinalStart after the end year");
}
// AnnualTimeZone#isEquavalentTo
if (!a1.isEquivalentTo(a2)) {
errln("FAIL: AnnualTimeZoneRule a1 is equivalent to a2, but returned false");
}
if (a1.isEquivalentTo(a3)) {
errln("FAIL: AnnualTimeZoneRule a1 is not equivalent to a3, but returned true");
}
if (!a1.isEquivalentTo(a1)) {
errln("FAIL: AnnualTimeZoneRule a1 is equivalent to itself, but returned false");
}
if (a1.isEquivalentTo(t1)) {
errln("FAIL: AnnualTimeZoneRule is not equivalent to TimeArrayTimeZoneRule, but returned true");
}
// AnnualTimeZone#isTransitionRule
if (!a1.isTransitionRule()) {
errln("FAIL: An AnnualTimeZoneRule is a transition rule, but returned false");
}
// AnnualTimeZone#toString
String str = a1.toString();
if (str == null || str.length() == 0) {
errln("FAIL: AnnualTimeZoneRule#toString for a1 returns null or empty string");
} else {
logln("AnnualTimeZoneRule a1 : " + str);
}
str = a3.toString();
if (str == null || str.length() == 0) {
errln("FAIL: AnnualTimeZoneRule#toString for a3 returns null or empty string");
} else {
logln("AnnualTimeZoneRule a3 : " + str);
}