jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1590132 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java
Date Fri, 25 Apr 2014 20:33:38 GMT
Author: jukka
Date: Fri Apr 25 20:33:38 2014
New Revision: 1590132

URL: http://svn.apache.org/r1590132
Log:
JCR-3775: Avoid lock contention in ISO8601.parse()

We actually do need flyweight instances of other known time zones than just GMT.
Add the ones listed in http://en.wikipedia.org/wiki/List_of_UTC_time_offsets.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java?rev=1590132&r1=1590131&r2=1590132&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java
Fri Apr 25 20:33:38 2014
@@ -18,6 +18,8 @@ package org.apache.jackrabbit.util;
 
 import java.util.Calendar;
 import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.TimeZone;
 
 /**
@@ -47,7 +49,31 @@ import java.util.TimeZone;
  */
 public final class ISO8601 {
 
-    private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+    /**
+     * Flyweight instances of known time zones.
+     */
+    private static final Map<String, TimeZone> TZS =
+            new HashMap<String, TimeZone>();
+
+    static {
+        TimeZone gmt = TimeZone.getTimeZone("GMT");
+        TZS.put("Z", gmt);
+        TZS.put("+00:00", gmt);
+        TZS.put("-00:00", gmt);
+
+        // http://en.wikipedia.org/wiki/List_of_UTC_time_offsets
+        String[] tzs = {
+                "-12:00", "-11:00", "-10:00", "-09:30", "-09:00", "-08:00",
+                "-07:00", "-06:00", "-05:00", "-04:30", "-04:00", "-03:30",
+                "-03:00", "-02:00", "-01:00", "+01:00", "+02:00", "+03:00",
+                "+03:30", "+04:00", "+04:30", "+05:00", "+05:30", "+05:45",
+                "+06:00", "+06:30", "+07:00", "+08:00", "+08:45", "+09:00",
+                "+09:30", "+10:00", "+10:30", "+11:00", "+11:30", "+12:00",
+                "+12:45", "+13:00", "+14:00" };
+        for (String tz : tzs) {
+            TZS.put(tz, TimeZone.getTimeZone("GMT" + tz));
+        }
+    }
 
     /**
      * Parses an ISO8601-compliant date/time string.
@@ -140,9 +166,8 @@ public final class ISO8601 {
             start += 3;
             // time zone designator (Z or +00:00 or -00:00)
             String tzid = text.substring(start);
-            if (tzid.equals("Z")) {
-                tz = GMT;
-            } else {
+            tz = TZS.get(tzid);
+            if (tz == null) {
                 // offset to UTC specified in the format +00:00/-00:00
                 tzid = "GMT" + tzid;
                 tz = TimeZone.getTimeZone(tzid);



Mime
View raw message