commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joe...@apache.org
Subject svn commit: r1146138 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/time/FastDateFormat.java test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
Date Wed, 13 Jul 2011 17:01:37 GMT
Author: joehni
Date: Wed Jul 13 17:01:37 2011
New Revision: 1146138

URL: http://svn.apache.org/viewvc?rev=1146138&view=rev
Log:
Adjust FastDateFormat for Java 7 behavior regarding format of the year pattern (LANG-719).

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java?rev=1146138&r1=1146137&r2=1146138&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java
Wed Jul 13 17:01:37 2011
@@ -47,7 +47,7 @@ import org.apache.commons.lang3.Validate
  * </p>
  *
  * <p>Only formatting is supported, but all patterns are compatible with
- * SimpleDateFormat (except time zones - see below).</p>
+ * SimpleDateFormat (except time zones and some year patterns - see below).</p>
  *
  * <p>Java 1.4 introduced a new pattern letter, {@code 'Z'}, to represent
  * time zones in RFC822 format (eg. {@code +0800} or {@code -1100}).
@@ -58,6 +58,12 @@ import org.apache.commons.lang3.Validate
  * This introduces a minor incompatibility with Java 1.4, but at a gain of
  * useful functionality.</p>
  *
+ * <p>Javadoc cites for the year pattern: <i>For formatting, if the number of
+ * pattern letters is 2, the year is truncated to 2 digits; otherwise it is
+ * interpreted as a number.</i> Starting with Java 1.7 a pattern of 'Y' or
+ * 'YYY' will be formatted as '2003', while it was '03' in former Java
+ * versions. FastDateFormat implements the behavior of Java 7.</p>
+ *
  * @since 2.0
  * @version $Id$
  */
@@ -486,10 +492,10 @@ public class FastDateFormat extends Form
                 rule = new TextField(Calendar.ERA, ERAs);
                 break;
             case 'y': // year (number)
-                if (tokenLen >= 4) {
-                    rule = selectNumberRule(Calendar.YEAR, tokenLen);
-                } else {
+                if (tokenLen == 2) {
                     rule = TwoDigitYearField.INSTANCE;
+                } else {
+                    rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
                 }
                 break;
             case 'M': // month in year (text and number)

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java?rev=1146138&r1=1146137&r2=1146138&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
Wed Jul 13 17:01:37 2011
@@ -216,8 +216,9 @@ public class FastDateFormatTest extends 
                 " dddd ddd dd d DDDD DDD DD D EEEE EEE EE E aaaa aaa aa a zzzz zzz zz z";
             fdf = FastDateFormat.getInstance(pattern);
             sdf = new SimpleDateFormat(pattern);
-            assertEquals(sdf.format(date1), fdf.format(date1));
-            assertEquals(sdf.format(date2), fdf.format(date2));
+            // SDF bug fix starting with Java 7
+            assertEquals(sdf.format(date1).replaceAll("2003 03 03 03", "2003 2003 03 2003"),
fdf.format(date1));
+            assertEquals(sdf.format(date2).replaceAll("2003 03 03 03", "2003 2003 03 2003"),
fdf.format(date2));
         } finally {
             Locale.setDefault(realDefaultLocale);
             TimeZone.setDefault(realDefaultZone);



Mime
View raw message