Author: niallp
Date: Sun Jan 31 00:53:56 2010
New Revision: 904941

URL: http://svn.apache.org/viewvc?rev=904941&view=rev
Log:
Port LANG-538 to 2.x branch - 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/branches/LANG_2_X/src/main/java/org/apache/commons/lang/time/FastDateFormat.java
    
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/time/FastDateFormatTest.java

Modified: 
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/time/FastDateFormat.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/time/FastDateFormat.java?rev=904941&r1=904940&r2=904941&view=diff
==============================================================================
--- 
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/time/FastDateFormat.java
 (original)
+++ 
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/time/FastDateFormat.java
 Sun Jan 31 00:53:56 2010
@@ -867,6 +867,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/branches/LANG_2_X/src/test/java/org/apache/commons/lang/time/FastDateFormatTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/time/FastDateFormatTest.java?rev=904941&r1=904940&r2=904941&view=diff
==============================================================================
--- 
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/time/FastDateFormatTest.java
 (original)
+++ 
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/time/FastDateFormatTest.java
 Sun Jan 31 00:53:56 2010
@@ -331,4 +331,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));
+    }
 }


Reply via email to