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

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

c079f6
  *
c079f6
  * 

Only formatting is supported, but all patterns are compatible with

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

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

c079f6
  *
c079f6
  * 

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

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

c079f6
  *
c079f6
+ * 

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

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

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