diff --git a/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneRegression.java b/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneRegression.java index f962d7f994..75c1d799ff 100755 --- a/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneRegression.java +++ b/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneRegression.java @@ -846,6 +846,55 @@ public class TimeZoneRegression extends TestFmwk { logln("got IllegalArgumentException"); } } + + /** + * Test to see if DateFormat understands zone equivalency groups. It + * might seem that this should be a DateFormat test, but it's really a + * TimeZone test -- the changes to DateFormat are minor. + * + * We use two known, stable zones that shouldn't change much over time + * -- America/Vancouver and America/Los_Angeles. However, they MAY + * change at some point -- if that happens, replace them with any two + * zones in an equivalency group where one zone has localized name + * data, and the other doesn't, in some locale. + */ + public void TestJ449() { + String str; + + // Modify the following three as necessary. The two IDs must + // specify two zones in the same equivalency group. One must have + // locale data in 'loc'; the other must not. + String idWithLocaleData = "America/Los_Angeles"; + String idWithoutLocaleData = "America/Vancouver"; + Locale loc = new Locale("en", "", ""); + + TimeZone zoneWith = TimeZone.getTimeZone(idWithLocaleData); + TimeZone zoneWithout = TimeZone.getTimeZone(idWithoutLocaleData); + // Make sure we got valid zones + if (!(zoneWith.getID().equals(idWithLocaleData) && + zoneWithout.getID().equals(idWithoutLocaleData))) { + errln("Fail: Unable to create zones"); + } else { + GregorianCalendar calWith = new GregorianCalendar(zoneWith); + GregorianCalendar calWithout = new GregorianCalendar(zoneWithout); + SimpleDateFormat fmt = + new SimpleDateFormat("MMM d yyyy hh:mm a zzz", loc); + Date date = new Date(0L); + fmt.setCalendar(calWith); + String strWith = fmt.format(date); + fmt.setCalendar(calWithout); + String strWithout = fmt.format(date); + if (strWith.equals(strWithout)) { + logln("Ok: " + idWithLocaleData + " -> " + + strWith + "; " + idWithoutLocaleData + " -> " + + strWithout); + } else { + errln("FAIL: " + idWithLocaleData + " -> " + + strWith + "; " + idWithoutLocaleData + " -> " + + strWithout); + } + } + } } //eof diff --git a/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java b/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java index 3858cd3aa2..87d3ed9fac 100755 --- a/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java @@ -706,6 +706,24 @@ public class TimeZoneTest extends TestFmwk errln("The offset for 10AM, 10/17/98 should have been -5 hours, but we got " + (offset / millisPerHour) + " hours."); } + + public void TestEquivalencyGroups() { + String id = "America/Los_Angeles"; + int n = TimeZone.countEquivalentIDs(id); + if (n < 2) { + errln("FAIL: countEquivalentIDs(" + id + ") returned " + n + + ", expected >= 2"); + } + for (int i=0; i " + + strWith + "; " + idWithoutLocaleData + " -> " + + strWithout); + } else { + errln("FAIL: " + idWithLocaleData + " -> " + + strWith + "; " + idWithoutLocaleData + " -> " + + strWithout); + } + } + } } //eof diff --git a/icu4j/src/com/ibm/test/timezone/TimeZoneTest.java b/icu4j/src/com/ibm/test/timezone/TimeZoneTest.java index 3858cd3aa2..87d3ed9fac 100755 --- a/icu4j/src/com/ibm/test/timezone/TimeZoneTest.java +++ b/icu4j/src/com/ibm/test/timezone/TimeZoneTest.java @@ -706,6 +706,24 @@ public class TimeZoneTest extends TestFmwk errln("The offset for 10AM, 10/17/98 should have been -5 hours, but we got " + (offset / millisPerHour) + " hours."); } + + public void TestEquivalencyGroups() { + String id = "America/Los_Angeles"; + int n = TimeZone.countEquivalentIDs(id); + if (n < 2) { + errln("FAIL: countEquivalentIDs(" + id + ") returned " + n + + ", expected >= 2"); + } + for (int i=0; i