You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2008/06/06 03:56:46 UTC

svn commit: r663798 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/TimeZone.java test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java

Author: qiuxx
Date: Thu Jun  5 18:56:46 2008
New Revision: 663798

URL: http://svn.apache.org/viewvc?rev=663798&view=rev
Log:
Apply for HARMONY-5860, ([classlib][luni] Complement the Missing TimeZone IDs)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TimeZone.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TimeZone.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TimeZone.java?rev=663798&r1=663797&r2=663798&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TimeZone.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TimeZone.java Thu Jun  5 18:56:46 2008
@@ -72,6 +72,24 @@
             AvailableZones.put(zones[i].getID(), zones[i]);
         }
     }
+    
+    private static boolean isAvailableIDInICU(String name) {
+        String[] availableIDs = com.ibm.icu.util.TimeZone.getAvailableIDs();
+        for (int i = 0; i < availableIDs.length; i++) {
+            if (availableIDs[i].equals(name)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    private static void appendAvailableZones(String name) {
+        com.ibm.icu.util.TimeZone icuTZ = com.ibm.icu.util.TimeZone
+                .getTimeZone(name);
+        int raw = icuTZ.getRawOffset();
+        TimeZone zone = new SimpleTimeZone(raw, name);
+        AvailableZones.put(name, zone);
+    }
 
     /**
      * Constructs a new instance of this class.
@@ -104,16 +122,7 @@
      * @return an array of time zone ID strings
      */
     public static synchronized String[] getAvailableIDs() {
-        if (AvailableZones == null) {
-            initializeAvailable();
-        }
-        int length = AvailableZones.size();
-        String[] answer = new String[length];
-        Iterator<String> keys = AvailableZones.keySet().iterator();
-        for (int i = 0; i < length; i++) {
-            answer[i] = keys.next();
-        }
-        return answer;
+        return com.ibm.icu.util.TimeZone.getAvailableIDs();
     }
 
     /**
@@ -125,14 +134,13 @@
      * @return an array of time zone ID strings
      */
     public static synchronized String[] getAvailableIDs(int offset) {
-        if (AvailableZones == null) {
-            initializeAvailable();
-        }
-        int count = 0, length = AvailableZones.size();
+        String[] availableIDs = com.ibm.icu.util.TimeZone.getAvailableIDs();
+        int count = 0;
+        int length = availableIDs.length;
         String[] all = new String[length];
-        Iterator<TimeZone> zones = AvailableZones.values().iterator();
         for (int i = 0; i < length; i++) {
-            TimeZone tz = zones.next();
+            com.ibm.icu.util.TimeZone tz = com.ibm.icu.util.TimeZone
+                    .getTimeZone(availableIDs[i]);
             if (tz.getRawOffset() == offset) {
                 all[count++] = tz.getID();
             }
@@ -303,7 +311,11 @@
             initializeAvailable();
         }
 
-        TimeZone zone = AvailableZones.get(name);
+        TimeZone zone = AvailableZones.get(name);        
+        if(zone == null && isAvailableIDInICU(name)){
+            appendAvailableZones(name);
+            zone = AvailableZones.get(name); 
+        }
         if (zone == null) {
             if (name.startsWith("GMT") && name.length() > 3) {
                 char sign = name.charAt(3);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java?rev=663798&r1=663797&r2=663798&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java Thu Jun  5 18:56:46 2008
@@ -18,6 +18,7 @@
 package org.apache.harmony.luni.tests.java.util;
 
 import java.util.Calendar;
+import java.util.Date;
 import java.util.Formatter;
 import java.util.GregorianCalendar;
 import java.util.Locale;
@@ -147,8 +148,9 @@
                              "GMT+05:20", TimeZone.getTimeZone("GMT+520").getID());
 		assertEquals("Must return proper GMT formatted string for GMT+052 (eg. GMT+08:20).",
                              "GMT+00:52", TimeZone.getTimeZone("GMT+052").getID());
-		assertEquals("Must return proper GMT formatted string for GMT-0 (eg. GMT+08:20).",
-                             "GMT-00:00", TimeZone.getTimeZone("GMT-0").getID());
+        // GMT-0 is an available ID in ICU, so replace it with GMT-00
+		assertEquals("Must return proper GMT formatted string for GMT-00 (eg. GMT+08:20).",
+                             "GMT-00:00", TimeZone.getTimeZone("GMT-00").getID());
 	}
 
 	/**
@@ -188,6 +190,18 @@
         }
     }
     
+    /*
+     * Regression for HARMONY-5860
+     */
+    public void test_GetTimezoneOffset() {
+        // America/Toronto is lazy initialized 
+        TimeZone.setDefault(TimeZone.getTimeZone("America/Toronto"));
+        Date date = new Date(07, 2, 24);
+        assertEquals(300, date.getTimezoneOffset());
+        date = new Date(99, 8, 1);
+        assertEquals(240, date.getTimezoneOffset());
+    }
+    
 	protected void setUp() {
 	}