commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r891542 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang3/time/FastDateFormat.java test/org/apache/commons/lang3/time/FastDateFormatTest.java
Date Thu, 17 Dec 2009 06:04:29 GMT
Author: bayard
Date: Thu Dec 17 06:04:28 2009
New Revision: 891542

URL: http://svn.apache.org/viewvc?rev=891542&view=rev
Log:
Fixing LANG-538 - you need to call getTime() on a calendar sometimes to get it in the right
state, otherwise the timezone gets out of whack. 

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

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang3/time/FastDateFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang3/time/FastDateFormat.java?rev=891542&r1=891541&r2=891542&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang3/time/FastDateFormat.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang3/time/FastDateFormat.java Thu
Dec 17 06:04:28 2009
@@ -869,6 +869,7 @@
      */
     public StringBuffer format(Calendar calendar, StringBuffer buf) {
         if (mTimeZoneForced) {
+            calendar.getTime(); /// LANG-538
             calendar = (Calendar) calendar.clone();
             calendar.setTimeZone(mTimeZone);
         }

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang3/time/FastDateFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang3/time/FastDateFormatTest.java?rev=891542&r1=891541&r2=891542&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang3/time/FastDateFormatTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang3/time/FastDateFormatTest.java
Thu Dec 17 06:04:28 2009
@@ -333,4 +333,17 @@
         format = (FastDateFormat) SerializationUtils.deserialize( SerializationUtils.serialize(
format ) );
         assertEquals(output, format.format(cal));
     }
+
+    public void testLang538() {
+        final String dateTime = "2009-10-16T16:42:16.000Z";
+
+        // more commonly constructed with: cal = new GregorianCalendar(2009, 9, 16, 8, 42,
16)
+        // for the unit test to work in any time zone, constructing with GMT-8 rather than
default locale time zone
+        GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT-8"));
+        cal.clear();
+        cal.set(2009, 9, 16, 8, 42, 16);
+
+        FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
TimeZone.getTimeZone("GMT"));
+        assertEquals("dateTime", dateTime, format.format(cal));
+    }
 }



Mime
View raw message