From 78b64c3fe8c14d61a34e2b76a09c773d92fc1471 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Mon, 15 Feb 2016 16:10:42 +0100 Subject: [PATCH] Fix parsing of ISO dates with UTC TZ --- ...Fix-parsing-of-ISO-dates-with-UTC-TZ.patch | 62 +++++++++++++++++++ apache-commons-lang3.spec | 6 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 0001-Fix-parsing-of-ISO-dates-with-UTC-TZ.patch diff --git a/0001-Fix-parsing-of-ISO-dates-with-UTC-TZ.patch b/0001-Fix-parsing-of-ISO-dates-with-UTC-TZ.patch new file mode 100644 index 0000000..c7d5371 --- /dev/null +++ b/0001-Fix-parsing-of-ISO-dates-with-UTC-TZ.patch @@ -0,0 +1,62 @@ +From 5986eae18fc6006ac4b39c35a7cb7ced8e70c61e Mon Sep 17 00:00:00 2001 +From: Michael Simacek +Date: Mon, 15 Feb 2016 15:02:45 +0100 +Subject: [PATCH] Fix parsing of ISO dates with UTC TZ + +--- + .../java/org/apache/commons/lang3/time/DateUtils.java | 3 ++- + .../org/apache/commons/lang3/time/DateUtilsTest.java | 17 ++++++++++++----- + 2 files changed, 14 insertions(+), 6 deletions(-) + +diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java b/src/main/java/org/apache/commons/lang3/time/DateUtils.java +index 7535b8b..8312031 100644 +--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java ++++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java +@@ -390,7 +390,8 @@ public class DateUtils { + String str2 = str; + // LANG-530 - need to make sure 'ZZ' output doesn't hit SimpleDateFormat as it will ParseException + if (parsePattern.endsWith("ZZ")) { +- str2 = str.replaceAll("([-+][0-9][0-9]):([0-9][0-9])$", "$1$2"); ++ str2 = str.replaceAll("([-+][0-9][0-9]):([0-9][0-9])$", "$1$2"); ++ str2 = str2.replaceAll("Z$", "+0000"); + } + + final Date date = parser.parse(str2, pos); +diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java +index 7ef0b8a..a20cf3f 100644 +--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java ++++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java +@@ -30,6 +30,7 @@ import java.lang.reflect.Modifier; + import java.text.DateFormat; + import java.text.ParseException; + import java.text.SimpleDateFormat; ++import java.time.ZoneId; + import java.util.Calendar; + import java.util.Date; + import java.util.GregorianCalendar; +@@ -1218,11 +1219,17 @@ public class DateUtilsTest { + // http://issues.apache.org/jira/browse/LANG-530 + @Test + public void testLang530() throws ParseException { +- final Date d = new Date(); +- final String isoDateStr = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(d); +- final Date d2 = DateUtils.parseDate(isoDateStr, new String[] { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() }); +- // the format loses milliseconds so have to reintroduce them +- assertEquals("Date not equal to itself ISO formatted and parsed", d.getTime(), d2.getTime() + d.getTime() % 1000); ++ for (long i = 1455545305000L; i <= 1455545306000L; i += 43) { ++ for (String id : ZoneId.getAvailableZoneIds()) { ++ final Date d = new Date(i); ++ FastDateFormat fmt = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ssZZ", TimeZone.getTimeZone(id)); ++ final String isoDateStr = fmt.format(d); ++ final Date d2 = DateUtils.parseDate(isoDateStr, new String[] { fmt.getPattern() }); ++ // the format loses milliseconds so have to reintroduce them ++ assertEquals("Date not equal to itself ISO formatted and parsed", d.getTime(), ++ d2.getTime() + d.getTime() % 1000); ++ } ++ } + } + + /** +-- +2.5.0 + diff --git a/apache-commons-lang3.spec b/apache-commons-lang3.spec index 34ae1a0..efd8841 100644 --- a/apache-commons-lang3.spec +++ b/apache-commons-lang3.spec @@ -3,7 +3,7 @@ Name: apache-%{short_name} Version: 3.4 -Release: 3%{?dist} +Release: 4%{?dist} Summary: Provides a host of helper utilities for the java.lang API License: ASL 2.0 URL: http://commons.apache.org/%{base_name} @@ -12,6 +12,7 @@ BuildArch: noarch # testParseSync() test fails on ARM and PPC64LE for unknown reason Patch0: fix-ppc64le-test-failure.patch +Patch1: 0001-Fix-parsing-of-ISO-dates-with-UTC-TZ.patch BuildRequires: maven-local BuildRequires: mvn(commons-io:commons-io) @@ -63,6 +64,9 @@ Summary: API documentation for %{name} %doc LICENSE.txt NOTICE.txt %changelog +* Mon Feb 15 2016 Michael Simacek - 3.4-4 +- Fix parsing of ISO dates with UTC TZ + * Wed Feb 03 2016 Fedora Release Engineering - 3.4-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild