From 077d3a16e073f9bfd873321e7e617cd88e286dc0 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Tue, 27 Sep 2011 23:52:04 +0000 Subject: [PATCH] ICU-8779 add UNKNOWN_ZONE & GMT_ZONE X-SVN-Rev: 30728 --- .../core/src/com/ibm/icu/util/TimeZone.java | 35 ++++++++++++++++--- .../icu/dev/test/timezone/TimeZoneTest.java | 10 ++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java index debdaf05d70..555ba443685 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java @@ -213,6 +213,32 @@ abstract public class TimeZone implements Serializable, Cloneable { */ public static final String UNKNOWN_ZONE_ID = "Etc/Unknown"; + /** + * {@icu} The "unknown" time zone. + * It behaves like the GMT/UTC time zone but has the UNKNOWN_ZONE_ID = "Etc/Unknown". + * {@link TimeZone#getTimeZone(String)} returns a mutable clone of this + * time zone if the input ID is not recognized. + * + *

In the future, this object will become immutable. + * @see #UNKNOWN_ZONE_ID + * @see #getTimeZone(String) + * + * @draft ICU 49 + * @provisional This API might change or be removed in a future release. + */ + public static final TimeZone UNKNOWN_ZONE = new SimpleTimeZone(0, UNKNOWN_ZONE_ID); + + /** + * {@icu} The GMT (=UTC) time zone. Its ID is "Etc/GMT". + * + *

In the future, this object will become immutable. + * @see #UNKNOWN_ZONE + * + * @draft ICU 49 + * @provisional This API might change or be removed in a future release. + */ + public static final TimeZone GMT_ZONE = new SimpleTimeZone(0, "Etc/GMT"); + /** * {@icu} System time zone type constants used by filtering zones in * {@link TimeZone#getAvailableIDs(SystemTimeZoneType, String, Integer)} @@ -619,9 +645,9 @@ abstract public class TimeZone implements Serializable, Cloneable { * or a custom ID such as "GMT-8:00". Note that the support of abbreviations, * such as "PST", is for JDK 1.1.x compatibility only and full names should be used. * - * @return the specified TimeZone, or the GMT zone with ID "Etc/Unknown" + * @return the specified TimeZone, or a mutable clone of the UNKNOWN_ZONE * if the given ID cannot be understood. - * @see #UNKNOWN_ZONE_ID + * @see #UNKNOWN_ZONE * @stable ICU 2.0 */ public static synchronized TimeZone getTimeZone(String ID) { @@ -635,8 +661,9 @@ abstract public class TimeZone implements Serializable, Cloneable { * "PST", is for JDK 1.1.x compatibility only and full names should be used. * @param type Time zone type, either TIMEZONE_ICU or * TIMEZONE_JDK. - * @return the specified TimeZone, or the GMT zone if the given ID + * @return the specified TimeZone, or a mutable clone of the UNKNOWN_ZONE if the given ID * cannot be understood. + * @see #UNKNOWN_ZONE * @stable ICU 4.0 */ public static synchronized TimeZone getTimeZone(String ID, int type) { @@ -666,7 +693,7 @@ abstract public class TimeZone implements Serializable, Cloneable { TimeZoneLogger.warning( "\"" +ID + "\" is a bogus id so timezone is falling back to Etc/Unknown(GMT)."); } - result = new SimpleTimeZone(0, UNKNOWN_ZONE_ID); + result = (TimeZone)UNKNOWN_ZONE.clone(); // TODO(yoshito): cloneAsThawed() } } return result; diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java index be542b82747..ba2783d113e 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java @@ -1802,6 +1802,16 @@ public class TimeZoneTest extends TestFmwk } } } + + public void TestZoneFields() { + assertEquals("UNKNOWN_ZONE wrong ID", "Etc/Unknown", TimeZone.UNKNOWN_ZONE.getID()); + assertEquals("UNKNOWN_ZONE wrong offset", 0, TimeZone.UNKNOWN_ZONE.getRawOffset()); + assertFalse("UNKNOWN_ZONE uses DST", TimeZone.UNKNOWN_ZONE.useDaylightTime()); + + assertEquals("GMT_ZONE wrong ID", "Etc/GMT", TimeZone.GMT_ZONE.getID()); + assertEquals("GMT_ZONE wrong offset", 0, TimeZone.GMT_ZONE.getRawOffset()); + assertFalse("GMT_ZONE uses DST", TimeZone.GMT_ZONE.useDaylightTime()); + } } //eof -- 2.40.0