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

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

64a261
  *
64a261
  * 

Only formatting is supported, but all patterns are compatible with

64a261
- * SimpleDateFormat (except time zones - see below).

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

64a261
  *
64a261
  * 

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

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

64a261
  *
64a261
+ * 

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

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

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