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

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

a49f28
  *
a49f28
  * 

Only formatting is supported, but all patterns are compatible with

a49f28
- * SimpleDateFormat (except time zones - see below).

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

a49f28
  *
a49f28
  * 

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

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

a49f28
  *
a49f28
+ * 

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

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

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