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);
}
// InitialTimeZoneRule#isEquivalentRule
if (!i1.isEquivalentTo(i2)) {
errln("FAIL: InitialTimeZoneRule i1 is equivalent to i2, but returned false");
}
if (i1.isEquivalentTo(i3)) {
errln("FAIL: InitialTimeZoneRule i1 is not equivalent to i3, but returned true");
}
if (i1.isEquivalentTo(a1)) {
errln("FAIL: An InitialTimeZoneRule is not equivalent to an AnnualTimeZoneRule, but returned true");
}
// InitialTimeZoneRule#getFirstStart/getFinalStart/getNextStart/getPreviousStart
d1 = i1.getFirstStart(0, 0);
if (d1 != null) {
errln("FAIL: Non-null Date is returned by InitialTimeZone#getFirstStart");
}
d1 = i1.getFinalStart(0, 0);
if (d1 != null) {
errln("FAIL: Non-null Date is returned by InitialTimeZone#getFinalStart");
}
d1 = i1.getNextStart(time1, 0, 0, false);
if (d1 != null) {
errln("FAIL: Non-null Date is returned by InitialTimeZone#getNextStart");
}
d1 = i1.getPreviousStart(time1, 0, 0, false);
if (d1 != null) {
errln("FAIL: Non-null Date is returned by InitialTimeZone#getPreviousStart");
}
// InitialTimeZoneRule#isTransitionRule
if (i1.isTransitionRule()) {
errln("FAIL: An InitialTimeZoneRule is not a transition rule, but returned true");
}
// InitialTimeZoneRule#toString
str = i1.toString();
if (str == null || str.length() == 0) {
errln("FAIL: InitialTimeZoneRule#toString returns null or empty string");
} else {
logln("InitialTimeZoneRule i1 : " + str);
}
// TimeArrayTimeZoneRule#getStartTimes
long[] times = t1.getStartTimes();
if (times == null || times.length == 0 || times[0] != 0) {
errln("FAIL: Bad start times are returned by TimeArrayTimeZoneRule#getStartTimes");
}
// TimeArrayTimeZoneRule#getTimeType
if (t1.getTimeType() != DateTimeRule.UTC_TIME) {
errln("FAIL: TimeArrayTimeZoneRule t1 uses UTC_TIME, but different type is returned");
}
if (t4.getTimeType() != DateTimeRule.STANDARD_TIME) {
errln("FAIL: TimeArrayTimeZoneRule t4 uses STANDARD_TIME, but different type is returned");
}
if (t5.getTimeType() != DateTimeRule.WALL_TIME) {
errln("FAIL: TimeArrayTimeZoneRule t5 uses WALL_TIME, but different type is returned");
}
// TimeArrayTimeZoneRule#getFirstStart/getFinalStart
d1 = t1.getFirstStart(0, 0);
if (d1 == null || d1.getTime() != trtimes1[0]) {
errln("FAIL: Bad first start time returned from TimeArrayTimeZoneRule t1");
}
d1 = t1.getFinalStart(0, 0);
if (d1 == null || d1.getTime() != trtimes1[0]) {
errln("FAIL: Bad final start time returned from TimeArrayTimeZoneRule t1");
}
d1 = t4.getFirstStart(-4*HOUR, 1*HOUR);
if (d1 == null || (d1.getTime() != trtimes1[0] + 4*HOUR)) {
errln("FAIL: Bad first start time returned from TimeArrayTimeZoneRule t4");
}
d1 = t5.getFirstStart(-4*HOUR, 1*HOUR);
if (d1 == null || (d1.getTime() != trtimes1[0] + 3*HOUR)) {
errln("FAIL: Bad first start time returned from TimeArrayTimeZoneRule t5");
}
// TimeArrayTimeZoneRule#getNextStart/getPreviousStart