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 18:08:39 UTC
svn commit: r1744443 -
/pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java
Author: tilman
Date: Wed May 18 18:08:39 2016
New Revision: 1744443
URL: http://svn.apache.org/viewvc?rev=1744443&view=rev
Log:
PDFBOX-3352: set zone id
Modified:
pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java
Modified: pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java?rev=1744443&r1=1744442&r2=1744443&view=diff
==============================================================================
--- pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java (original)
+++ pdfbox/branches/1.8/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java Wed May 18 18:08:39 2016
@@ -28,6 +28,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 date standards. Date are described in
@@ -174,6 +175,7 @@ public class DateConverter
}
else
{
+ updateZoneId(zone);
retval = new GregorianCalendar(zone);
}
retval.clear();
@@ -217,6 +219,43 @@ public class DateConverter
}
/**
+ * 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");
+ }
+ }
+
+ /**
* Append Zero to String Buffer before number < 10 ('1' become '01')
*
* @param out