You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/05/20 11:29:50 UTC

svn commit: r1744716 - /pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java

Author: tilman
Date: Fri May 20 11:29:50 2016
New Revision: 1744716

URL: http://svn.apache.org/viewvc?rev=1744716&view=rev
Log:
PDFBOX-3352: set zone id

Modified:
    pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java?rev=1744716&r1=1744715&r2=1744716&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java Fri May 20 11:29:50 2016
@@ -190,6 +190,7 @@ public final class DateConverter
                 }
                 else
                 {
+                    updateZoneId(zone);
                     retval = new GregorianCalendar(zone);
                 }
                 retval.clear();
@@ -229,7 +230,43 @@ public final class DateConverter
         }
         return retval;
     }
-    
+
+    /**
+     * Update the zone ID based on the raw offset. This is either GMT, GMT+hh:mm or GMT-hh:mm, where
+     * n is between 1 and 14. The highest negative hour is -14, the highest positive hour is 12.
+     * Zones that don't fit in this schema are set to zone ID "unknown".
+     *
+     * @param tz the time zone to update.
+     */
+    private static void updateZoneId(TimeZone tz)
+    {
+        int offset = tz.getRawOffset();
+        char pm = '+';
+        if (offset < 0)
+        {
+            pm = '-';
+            offset = -offset;
+        }
+        int hh = offset / 3600000;
+        int mm = offset % 3600000 / 60000;
+        if (offset == 0)
+        {
+            tz.setID("GMT");
+        }
+        else if (pm == '+' && hh <= 12)
+        {
+            tz.setID(String.format("GMT+%02d:%02d", hh, mm));
+        }
+        else if (pm == '-' && hh <= 14)
+        {
+            tz.setID(String.format("GMT-%02d:%02d", hh, mm));
+        }
+        else
+        {
+            tz.setID("unknown");
+        }
+    }
+
     /**
      * Convert the date to iso 8601 string format.
      *