pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1755623 - in /pdfbox/branches/2.0/pdfbox/src: main/java/org/apache/pdfbox/util/DateConverter.java test/java/org/apache/pdfbox/util/TestDateUtil.java
Date Tue, 09 Aug 2016 15:30:02 GMT
Author: tilman
Date: Tue Aug  9 15:30:01 2016
New Revision: 1755623

URL: http://svn.apache.org/viewvc?rev=1755623&view=rev
Log:
PDFBOX-3315: prevent corner case 12:00 to be interpreted as 00:00, fixed + added tests

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java
    pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java?rev=1755623&r1=1755622&r2=1755623&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java Tue
Aug  9 15:30:01 2016
@@ -197,12 +197,16 @@ public final class DateConverter
     }
     
     /*
-     * Constrain a timezone offset to the range  [-11:59 thru +11:59].
+     * Constrain a timezone offset to the range  [-11:59 thru +12:00].
      * by adding or subtracting multiples of a full day.
      */
     private static int restrainTZoffset(long proposedOffset)
     {
         proposedOffset = ((proposedOffset + HALF_DAY) % DAY + DAY) % DAY;
+        if (proposedOffset == 0)
+        {
+            return HALF_DAY;
+        }
         // 0 <= proposedOffset < DAY
         proposedOffset = (proposedOffset - HALF_DAY) % HALF_DAY;
         // -HALF_DAY < proposedOffset < HALF_DAY

Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java?rev=1755623&r1=1755622&r2=1755623&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java Tue
Aug  9 15:30:01 2016
@@ -295,6 +295,8 @@ public class TestDateUtil extends TestCa
             // ambiguous big-endian date
             checkParse(2073,12,25, 0, 8, 0, 0, 0, "2073 12 25:08"); 
             
+            // PDFBOX-3315 GMT+12
+            checkParse(2016, 4,11,16,01,15, 12, 0, "D:20160411160115+12'00'");   
     }
 
     private static void checkToString(int yr, int mon, int day, 
@@ -370,6 +372,7 @@ public class TestDateUtil extends TestCa
      */
     public void testParseTZ() 
     {
+        // 1st parameter is what to expect
         checkParseTZ(0*HRS+0*MINS, "+00:00");
         checkParseTZ(0*HRS+0*MINS, "-0000");
         checkParseTZ(1*HRS+0*MINS, "+1:00");
@@ -391,6 +394,9 @@ public class TestDateUtil extends TestCa
         checkParseTZ((5*HRS+0*MINS), "+0500");
         checkParseTZ((11*HRS+0*MINS), "+11'00'");
         checkParseTZ(0, "Z");
+        // PDFBOX-3315
+        checkParseTZ(12*HRS+0*MINS, "+12:00");
+        checkParseTZ(12*HRS+0*MINS, "-12:00");
     }
     
     private static void checkFormatOffset(double off, String expect) 
@@ -405,6 +411,7 @@ public class TestDateUtil extends TestCa
      */
     public void testFormatTZoffset()
     {
+        // 2nd parameter is what to expect
         checkFormatOffset(-12.1, "+11:54");
         checkFormatOffset(12.1, "-11:54");
         checkFormatOffset(0, "+00:00");
@@ -413,8 +420,8 @@ public class TestDateUtil extends TestCa
         checkFormatOffset(-0.5, "-00:30");
         checkFormatOffset(.1, "+00:06");
         checkFormatOffset(-0.1, "-00:06");
-        checkFormatOffset(-12, "+00:00");
-        checkFormatOffset(12, "+00:00");
+        checkFormatOffset(-12, "+12:00");
+        checkFormatOffset(12, "+12:00");
         checkFormatOffset(-11.5, "-11:30");
         checkFormatOffset(11.5, "+11:30");
         checkFormatOffset(11.9, "+11:54");



Mime
View raw message