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:30:05 UTC

svn commit: r1744717 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java

Author: tilman
Date: Fri May 20 11:30:05 2016
New Revision: 1744717

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

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java?rev=1744717&r1=1744716&r2=1744717&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java Fri May 20 11:30:05 2016
@@ -432,7 +432,7 @@ public final class DateConverter
             int hrSign = (sign == '-' ? -1 : 1);
             tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin *
                                                        (long) MILLIS_PER_MINUTE)));
-            tz.setID("unknown");
+            updateZoneId(tz);                       
         }
         else if ( ! hadGMT)
         {
@@ -455,7 +455,43 @@ public final class DateConverter
         initialWhere.setIndex(where.getIndex());
         return true;
     }
-    
+
+    /**
+     * 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");
+        }
+    }
+
     /*
      * Parses a big-endian date: year month day hour min sec.
      * The year must be four digits. Other fields may be adjacent