BasicTimeZone btz = (BasicTimeZone)TimeZone.getTimeZone(ids[zidx], TimeZone.TIMEZONE_ICU);
TimeZone tz = TimeZone.getTimeZone(ids[zidx]);
sdf.setTimeZone(tz);
long t = START_TIME;
TimeZoneTransition tzt = null;
boolean middle = true;
while (t < END_TIME) {
if (tzt == null) {
testTimes[0] = t;
expectedRoundTrip[0] = true;
testLen = 1;
} else {
int fromOffset = tzt.getFrom().getRawOffset() + tzt.getFrom().getDSTSavings();
int toOffset = tzt.getTo().getRawOffset() + tzt.getTo().getDSTSavings();
int delta = toOffset - fromOffset;
if (delta < 0) {
boolean isDstDecession = tzt.getFrom().getDSTSavings() > 0 && tzt.getTo().getDSTSavings() == 0;
testTimes[0] = t + delta - 1;
expectedRoundTrip[0] = true;
testTimes[1] = t + delta;
expectedRoundTrip[1] = isDstDecession ?
!AMBIGUOUS_DST_DECESSION[patidx] : !AMBIGUOUS_NEGATIVE_SHIFT[patidx];
testTimes[2] = t - 1;
expectedRoundTrip[2] = isDstDecession ?
!AMBIGUOUS_DST_DECESSION[patidx] : !AMBIGUOUS_NEGATIVE_SHIFT[patidx];
testTimes[3] = t;
expectedRoundTrip[3] = true;
testLen = 4;
} else {
testTimes[0] = t - 1;
expectedRoundTrip[0] = true;
testTimes[1] = t;
expectedRoundTrip[1] = true;
testLen = 2;
}
}
for (int testidx = 0; testidx < testLen; testidx++) {
testCounts++;
timer = System.currentTimeMillis();
String text = sdf.format(new Date(testTimes[testidx]));
try {
Date parsedDate = sdf.parse(text);
long restime = parsedDate.getTime();
if (restime != testTimes[testidx]) {
StringBuffer msg = new StringBuffer();
msg.append("Time round trip failed for ")
.append("tzid=").append(ids[zidx])
.append(", locale=").append(LOCALES[locidx])
.append(", pattern=").append(PATTERNS[patidx])
.append(", text=").append(text)
.append(", gmt=").append(sdfGMT.format(new Date(testTimes[testidx])))
.append(", time=").append(testTimes[testidx])
.append(", restime=").append(restime)
.append(", diff=").append(restime - testTimes[testidx]);
if (expectedRoundTrip[testidx]) {
errln("FAIL: " + msg.toString());
} else if (REALLY_VERBOSE) {
logln(msg.toString());
}
}
} catch (ParseException pe) {
errln("FAIL: " + pe.getMessage());
}
times[patidx] += System.currentTimeMillis() - timer;
}
tzt = btz.getNextTransition(t, false);
if (tzt == null) {
break;
}
if (middle) {
// Test the date in the middle of two transitions.
t += (tzt.getTime() - t)/2;
middle = false;
tzt = null;
} else {
t = tzt.getTime();
}
}
}
}
}