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

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

59af95
  *
59af95
  * 

Only formatting is supported, but all patterns are compatible with

59af95
- * SimpleDateFormat (except time zones - see below).

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

59af95
  *
59af95
  * 

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

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

59af95
  *
59af95
+ * 

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

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

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