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/08/11 16:40:08 UTC
svn commit: r1756009 - in /pdfbox/branches/1.8/pdfbox/src:
main/java/org/apache/pdfbox/util/DateConverter.java
test/java/org/apache/pdfbox/util/TestDateUtil.java
Author: tilman
Date: Thu Aug 11 16:40:08 2016
New Revision: 1756009
URL: http://svn.apache.org/viewvc?rev=1756009&view=rev
Log:
PDFBOX-2420: keep timezones -14:00 thru +14:00, adjust tests
Modified:
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java
pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java?rev=1756009&r1=1756008&r2=1756009&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/DateConverter.java Thu Aug 11 16:40:08 2016
@@ -227,13 +227,20 @@ public class DateConverter
}
/**
- * Constrain a timezone offset to the range [-11:59 thru +12:00].
+ * Constrain a timezone offset to the range [-14:00 thru +14:00].
* @param proposedOffset A value intended to be a timezone offset.
* @return The corresponding value reduced to the above noted range
* by adding or subtracting multiples of a full day.
*/
public static int restrainTZoffset(long proposedOffset)
{
+ if (proposedOffset <= 14 * MILLIS_PER_HOUR && proposedOffset >= -14 * MILLIS_PER_HOUR)
+ {
+ // https://www.w3.org/TR/xmlschema-2/#dateTime-timezones
+ // Timezones between 14:00 and -14:00 are valid
+ return (int) proposedOffset;
+ }
+ // Constrain a timezone offset to the range [-11:59 thru +12:00].
proposedOffset = ((proposedOffset+HALF_DAY)%DAY+DAY)%DAY;
if (proposedOffset == 0)
{
Modified: pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java?rev=1756009&r1=1756008&r2=1756009&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/util/TestDateUtil.java Thu Aug 11 16:40:08 2016
@@ -412,8 +412,8 @@ public class TestDateUtil extends TestCa
checkParseTZ(-(1*HRS+0*MINS), "-1:00");
checkParseTZ(-(1*HRS+30*MINS), "-0130");
checkParseTZ(11*HRS+59*MINS, "1159");
- checkParseTZ(-(11*HRS+30*MINS), "1230");
- checkParseTZ(11*HRS+30*MINS, "-12:30");
+ checkParseTZ(12*HRS+30*MINS, "1230");
+ checkParseTZ(-(12*HRS+30*MINS), "-12:30");
checkParseTZ(0*HRS+0*MINS, "Z");
checkParseTZ(-(8*HRS+0*MINS), "PST");
checkParseTZ(0*HRS+0*MINS, "EDT"); // EDT does not parse
@@ -429,9 +429,11 @@ public class TestDateUtil extends TestCa
checkParseTZ((5*HRS+0*MINS), "+0500");
checkParseTZ((11*HRS+0*MINS), "+11'00'");
checkParseTZ(0, "Z");
- // PDFBOX-3315
+ // PDFBOX-3315, PDFBOX-2420
checkParseTZ(12*HRS+0*MINS, "+12:00");
- checkParseTZ(12*HRS+0*MINS, "-12:00");
+ checkParseTZ(-(12*HRS+0*MINS), "-12:00");
+ checkParseTZ(14*HRS+0*MINS, "1400");
+ checkParseTZ(-(14*HRS+0*MINS), "-1400");
}
private static void checkFormatOffset(double off, String expect)
@@ -447,15 +449,15 @@ 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(-12.1, "-12:06");
+ checkFormatOffset(12.1, "+12:06");
checkFormatOffset(0, "+00:00");
checkFormatOffset(-1, "-01:00");
checkFormatOffset(.5, "+00:30");
checkFormatOffset(-0.5, "-00:30");
checkFormatOffset(.1, "+00:06");
checkFormatOffset(-0.1, "-00:06");
- checkFormatOffset(-12, "+12:00");
+ checkFormatOffset(-12, "-12:00");
checkFormatOffset(12, "+12:00");
checkFormatOffset(-11.5, "-11:30");
checkFormatOffset(11.5, "+11:30");
@@ -463,6 +465,9 @@ public class TestDateUtil extends TestCa
checkFormatOffset(11.1, "+11:06");
checkFormatOffset(-11.9, "-11:54");
checkFormatOffset(-11.1, "-11:06");
+ // PDFBOX-2420
+ checkFormatOffset(14, "+14:00");
+ checkFormatOffset(-14, "-14:00");
}
// testbody precedes