diff options
Diffstat (limited to 'luni/src')
-rw-r--r-- | luni/src/main/native/TimeZones.cpp | 9 | ||||
-rw-r--r-- | luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java | 18 | ||||
-rw-r--r-- | luni/src/test/java/libcore/java/util/TimeZoneTest.java | 11 |
3 files changed, 35 insertions, 3 deletions
diff --git a/luni/src/main/native/TimeZones.cpp b/luni/src/main/native/TimeZones.cpp index bb6cee9..146f90b 100644 --- a/luni/src/main/native/TimeZones.cpp +++ b/luni/src/main/native/TimeZones.cpp @@ -62,8 +62,17 @@ static jobjectArray TimeZones_forCountryCode(JNIEnv* env, jclass, jstring countr } static jstring TimeZones_getDisplayNameImpl(JNIEnv* env, jclass, jstring javaZoneId, jboolean isDST, jint style, jstring localeId) { + // Get an ICU4C TimeZone* for the given id. Really, we want TimeZone::createSystemTimeZone, + // but that's not public. Instead, we have to check we got the time zone we wanted, rather + // than a clone of GMT. (http://b/3394198 asks for ICU to expose the more useful method.) ScopedJavaUnicodeString zoneId(env, javaZoneId); UniquePtr<TimeZone> zone(TimeZone::createTimeZone(zoneId.unicodeString())); + UnicodeString actualZoneId; + zone->getID(actualZoneId); + if (actualZoneId != zoneId.unicodeString()) { + return NULL; + } + Locale locale = getLocale(env, localeId); // Try to get the display name of the TimeZone according to the Locale UnicodeString displayName; diff --git a/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java b/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java index 4da54e6..cbcf7e9 100644 --- a/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java +++ b/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java @@ -387,12 +387,24 @@ public class OldSimpleDateFormatTest extends junit.framework.TestCase { FormatTester test = new FormatTester(); Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6); - format.setTimeZone(new SimpleTimeZone(60000, "ONE MINUTE")); + TimeZone tz0001 = new SimpleTimeZone(60000, "ONE MINUTE"); + TimeZone tz0130 = new SimpleTimeZone(5400000, "ONE HOUR, THIRTY"); + TimeZone tzMinus0130 = new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY"); + + format.setTimeZone(tz0001); + test.test(" Z", cal, " +0001", DateFormat.TIMEZONE_FIELD); + test.test(" ZZZZ", cal, " +0001", DateFormat.TIMEZONE_FIELD); + format.setTimeZone(tz0130); + test.test(" Z", cal, " +0130", DateFormat.TIMEZONE_FIELD); + format.setTimeZone(tzMinus0130); + test.test(" Z", cal, " -0130", DateFormat.TIMEZONE_FIELD); + + format.setTimeZone(tz0001); test.test(" z", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD); test.test(" zzzz", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD); - format.setTimeZone(new SimpleTimeZone(5400000, "ONE HOUR, THIRTY")); + format.setTimeZone(tz0130); test.test(" z", cal, " GMT+01:30", DateFormat.TIMEZONE_FIELD); - format.setTimeZone(new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY")); + format.setTimeZone(tzMinus0130); test.test(" z", cal, " GMT-01:30", DateFormat.TIMEZONE_FIELD); format.setTimeZone(TimeZone.getTimeZone("America/New_York")); diff --git a/luni/src/test/java/libcore/java/util/TimeZoneTest.java b/luni/src/test/java/libcore/java/util/TimeZoneTest.java index dbde4ac..f7fe649 100644 --- a/luni/src/test/java/libcore/java/util/TimeZoneTest.java +++ b/luni/src/test/java/libcore/java/util/TimeZoneTest.java @@ -17,6 +17,7 @@ package libcore.java.util; import java.util.Date; +import java.util.Locale; import java.util.TimeZone; import java.util.SimpleTimeZone; @@ -40,4 +41,14 @@ public class TimeZoneTest extends junit.framework.TestCase { stz.inDaylightTime(new Date()); stz.clone(); } + + // http://b/3049014 + public void testCustomTimeZoneDisplayNames() { + TimeZone tz0001 = new SimpleTimeZone(60000, "ONE MINUTE"); + TimeZone tz0130 = new SimpleTimeZone(5400000, "ONE HOUR, THIRTY"); + TimeZone tzMinus0130 = new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY"); + assertEquals("GMT+00:01", tz0001.getDisplayName(false, TimeZone.SHORT, Locale.US)); + assertEquals("GMT+01:30", tz0130.getDisplayName(false, TimeZone.SHORT, Locale.US)); + assertEquals("GMT-01:30", tzMinus0130.getDisplayName(false, TimeZone.SHORT, Locale.US)); + } } |