Blame SOURCES/0002-Fix-FastDateFormat-for-Java-7-behaviour.patch

9809b3
From 6af11cb2cfdf83ce013a531005077259984c55e7 Mon Sep 17 00:00:00 2001
9809b3
From: Stanislav Ochotnicky <sochotnicky@redhat.com>
9809b3
Date: Wed, 22 Feb 2012 11:21:06 +0100
9809b3
Subject: [PATCH 2/2] Fix FastDateFormat for Java 7 behaviour
9809b3
9809b3
Backported from 1146138
9809b3
See https://issues.apache.org/jira/browse/LANG-719 for more information
9809b3
---
9809b3
 .../apache/commons/lang/time/FastDateFormat.java   |   14 ++++++++++----
9809b3
 .../commons/lang/time/FastDateFormatTest.java      |    5 +++--
9809b3
 2 files changed, 13 insertions(+), 6 deletions(-)
9809b3
9809b3
diff --git a/src/main/java/org/apache/commons/lang/time/FastDateFormat.java b/src/main/java/org/apache/commons/lang/time/FastDateFormat.java
9809b3
index 2ca7e5c..b7e19ec 100644
9809b3
--- a/src/main/java/org/apache/commons/lang/time/FastDateFormat.java
9809b3
+++ b/src/main/java/org/apache/commons/lang/time/FastDateFormat.java
9809b3
@@ -49,7 +49,7 @@ import org.apache.commons.lang.text.StrBuilder;
9809b3
  * 

9809b3
  *
9809b3
  * 

Only formatting is supported, but all patterns are compatible with

9809b3
- * SimpleDateFormat (except time zones - see below).

9809b3
+ * SimpleDateFormat (except time zones and some year patterns - see below).

9809b3
  *
9809b3
  * 

Java 1.4 introduced a new pattern letter, 'Z', to represent

9809b3
  * time zones in RFC822 format (eg. +0800 or -1100).
9809b3
@@ -60,6 +60,12 @@ import org.apache.commons.lang.text.StrBuilder;
9809b3
  * This introduces a minor incompatibility with Java 1.4, but at a gain of
9809b3
  * useful functionality.

9809b3
  *
9809b3
+ * 

Javadoc cites for the year pattern: For formatting, if the number of

9809b3
+ * pattern letters is 2, the year is truncated to 2 digits; otherwise it is
9809b3
+ * interpreted as a number. Starting with Java 1.7 a pattern of 'Y' or
9809b3
+ * 'YYY' will be formatted as '2003', while it was '03' in former Java
9809b3
+ * versions. FastDateFormat implements the behavior of Java 7.

9809b3
+ *
9809b3
  * @author Apache Software Foundation
9809b3
  * @author TeaTrove project
9809b3
  * @author Brian S O'Neill
9809b3
@@ -606,10 +612,10 @@ public class FastDateFormat extends Format {
9809b3
                 rule = new TextField(Calendar.ERA, ERAs);
9809b3
                 break;
9809b3
             case 'y': // year (number)
9809b3
-                if (tokenLen >= 4) {
9809b3
-                    rule = selectNumberRule(Calendar.YEAR, tokenLen);
9809b3
-                } else {
9809b3
+                if (tokenLen == 2) {
9809b3
                     rule = TwoDigitYearField.INSTANCE;
9809b3
+                } else {
9809b3
+                    rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
9809b3
                 }
9809b3
                 break;
9809b3
             case 'M': // month in year (text and number)
9809b3
diff --git a/src/test/java/org/apache/commons/lang/time/FastDateFormatTest.java b/src/test/java/org/apache/commons/lang/time/FastDateFormatTest.java
9809b3
index 8232747..bd4d664 100644
9809b3
--- a/src/test/java/org/apache/commons/lang/time/FastDateFormatTest.java
9809b3
+++ b/src/test/java/org/apache/commons/lang/time/FastDateFormatTest.java
9809b3
@@ -230,8 +230,9 @@ public class FastDateFormatTest extends TestCase {
9809b3
                 " dddd ddd dd d DDDD DDD DD D EEEE EEE EE E aaaa aaa aa a zzzz zzz zz z";
9809b3
             fdf = FastDateFormat.getInstance(pattern);
9809b3
             sdf = new SimpleDateFormat(pattern);
9809b3
-            assertEquals(sdf.format(date1), fdf.format(date1));
9809b3
-            assertEquals(sdf.format(date2), fdf.format(date2));
9809b3
+            // SDF bug fix starting with Java 7
9809b3
+            assertEquals(sdf.format(date1).replaceAll("2003 03 03 03", "2003 2003 03 2003"), fdf.format(date1));
9809b3
+            assertEquals(sdf.format(date2).replaceAll("2003 03 03 03", "2003 2003 03 2003"), fdf.format(date2));
9809b3
 
9809b3
         } finally {
9809b3
             Locale.setDefault(realDefaultLocale);
9809b3
-- 
9809b3
1.7.7.6
9809b3