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/18 14:56:55 UTC

svn commit: r1744417 - /pdfbox/branches/1.8/jempbox/src/main/java/org/apache/jempbox/impl/DateConverter.java

Author: tilman
Date: Wed May 18 14:56:54 2016
New Revision: 1744417

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

Modified:
    pdfbox/branches/1.8/jempbox/src/main/java/org/apache/jempbox/impl/DateConverter.java

Modified: pdfbox/branches/1.8/jempbox/src/main/java/org/apache/jempbox/impl/DateConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/jempbox/src/main/java/org/apache/jempbox/impl/DateConverter.java?rev=1744417&r1=1744416&r2=1744417&view=diff
==============================================================================
--- pdfbox/branches/1.8/jempbox/src/main/java/org/apache/jempbox/impl/DateConverter.java (original)
+++ pdfbox/branches/1.8/jempbox/src/main/java/org/apache/jempbox/impl/DateConverter.java Wed May 18 14:56:54 2016
@@ -23,6 +23,7 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.SimpleTimeZone;
+import java.util.TimeZone;
 
 /**
  * This class is used to convert dates to strings and back using the PDF
@@ -158,6 +159,7 @@ public class DateConverter
                 }
                 else
                 {
+                    updateZoneId(zone);
                     retval = new GregorianCalendar( zone );
                 }
                 retval.clear();
@@ -199,6 +201,43 @@ public 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)
+    {
+        // https://garygregory.wordpress.com/2013/06/18/what-are-the-java-timezone-ids/
+        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");
+        }
+    }
+
     private static final void zeroAppend( StringBuffer out, int number )
     {
         if( number < 10 )