Return-Path:
X-Original-To: apmail-commons-commits-archive@minotaur.apache.org
Delivered-To: apmail-commons-commits-archive@minotaur.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id 481DD64F9
for ;
Wed, 13 Jul 2011 17:02:00 +0000 (UTC)
Received: (qmail 58287 invoked by uid 500); 13 Jul 2011 17:02:00 -0000
Delivered-To: apmail-commons-commits-archive@commons.apache.org
Received: (qmail 58101 invoked by uid 500); 13 Jul 2011 17:01:59 -0000
Mailing-List: contact commits-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@commons.apache.org
Delivered-To: mailing list commits@commons.apache.org
Received: (qmail 58093 invoked by uid 99); 13 Jul 2011 17:01:59 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jul 2011 17:01:59 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=5.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jul 2011 17:01:57 +0000
Received: from eris.apache.org (localhost [127.0.0.1])
by eris.apache.org (Postfix) with ESMTP id D0EA823889E1
for ; Wed, 13 Jul 2011 17:01:37 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
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 -0000
To: commits@commons.apache.org
From: joehni@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20110713170137.D0EA823889E1@eris.apache.org>
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
*
*
* Only formatting is supported, but all patterns are compatible with
- * SimpleDateFormat (except time zones - see below).
+ * SimpleDateFormat (except time zones and some year patterns - see below).
*
* 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.
*
+ * Javadoc cites for the year pattern: For formatting, if the number of
+ * pattern letters is 2, the year is truncated to 2 digits; otherwise it is
+ * interpreted as a number. 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.
+ *
* @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);