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.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@891542 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
91ac16e0b4
commit
825481f019
|
@ -869,6 +869,7 @@ public class FastDateFormat extends Format {
|
|||
*/
|
||||
public StringBuffer format(Calendar calendar, StringBuffer buf) {
|
||||
if (mTimeZoneForced) {
|
||||
calendar.getTime(); /// LANG-538
|
||||
calendar = (Calendar) calendar.clone();
|
||||
calendar.setTimeZone(mTimeZone);
|
||||
}
|
||||
|
|
|
@ -333,4 +333,17 @@ public class FastDateFormatTest extends TestCase {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue