]> granicus.if.org Git - icu/commitdiff
ICU-8779 add UNKNOWN_ZONE & GMT_ZONE
authorMarkus Scherer <markus.icu@gmail.com>
Tue, 27 Sep 2011 23:52:04 +0000 (23:52 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Tue, 27 Sep 2011 23:52:04 +0000 (23:52 +0000)
X-SVN-Rev: 30728

icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java

index debdaf05d701402d40e9ee754500fa4eec045451..555ba44368560843b7c3d92e1de9e8180852417d 100644 (file)
@@ -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.
+     *
+     * <p>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".
+     *
+     * <p>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 <code>TimeZone</code>, or the GMT zone with ID "Etc/Unknown"
+     * @return the specified <code>TimeZone</code>, 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 <code>TIMEZONE_ICU</code> or
      * <code>TIMEZONE_JDK</code>.
-     * @return the specified <code>TimeZone</code>, or the GMT zone if the given ID
+     * @return the specified <code>TimeZone</code>, 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;
index be542b82747f3e75fd0751eaf92bf20eb7348d20..ba2783d113ee8746715582d1ac6213914339eb8f 100644 (file)
@@ -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