LOCALES = new ULocale[] {
new ULocale("en"),
};
}
SimpleDateFormat sdfGMT = new SimpleDateFormat(BASEPATTERN);
sdfGMT.setTimeZone(TimeZone.getTimeZone("Etc/GMT"));
long testCounts = 0;
long[] testTimes = new long[4];
boolean[] expectedRoundTrip = new boolean[4];
int testLen = 0;
for (int locidx = 0; locidx < LOCALES.length; locidx++) {
logln("Locale: " + LOCALES[locidx].toString());
for (int patidx = 0; patidx < PATTERNS.length; patidx++) {
logln(" pattern: " + PATTERNS[patidx]);
String pattern = BASEPATTERN + " " + PATTERNS[patidx];
SimpleDateFormat sdf = new SimpleDateFormat(pattern, LOCALES[locidx]);
String[] ids = TimeZone.getAvailableIDs();
for (int zidx = 0; zidx < ids.length; zidx++) {
String id = TimeZone.getCanonicalID(ids[zidx]);
if (id == null || !id.equals(ids[zidx])) {
// Skip aliases
continue;
}
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])