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

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

459ada
  *
459ada
  * 

Only formatting is supported, but all patterns are compatible with

459ada
- * SimpleDateFormat (except time zones - see below).

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

459ada
  *
459ada
  * 

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

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

459ada
  *
459ada
+ * 

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

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

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