commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Closed: (LANG-538) DateFormatUtils.format does not correctly change Calendar TimeZone in certain situations
Date Thu, 17 Dec 2009 06:06:18 GMT

     [ https://issues.apache.org/jira/browse/LANG-538?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Yandell closed LANG-538.
------------------------------

    Resolution: Fixed

Thanks for the report Jeff. I've inserted a getTime() into FastDateFormat that fixes your
test case, and hopefully extends to the general problem.

svn ci -m "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. " src
Sending        src/java/org/apache/commons/lang3/time/FastDateFormat.java
Sending        src/test/org/apache/commons/lang3/time/FastDateFormatTest.java
Transmitting file data ..
Committed revision 891542.


> DateFormatUtils.format does not correctly change Calendar TimeZone in certain situations
> ----------------------------------------------------------------------------------------
>
>                 Key: LANG-538
>                 URL: https://issues.apache.org/jira/browse/LANG-538
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 2.4
>         Environment: Sun JDK6, RHEL 5.3
>            Reporter: Jeff Peterson
>             Fix For: 3.0
>
>
> If a Calendar object is constructed in certain ways a call to Calendar.setTimeZone does
not correctly change the Calendars fields.  Calling Calenar.getTime() seems to fix this problem.
 While this is probably a bug in the JDK, it would be nice if DateFormatUtils was smart enough
to detect/resolve this problem.
> For example, the following unit test fails:
> {noformat}
>   public void testFormat_CalendarIsoMsZulu() {
>     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));
>   }
> {noformat}
> However, this unit test passes:
> {noformat}
>   public void testFormat_CalendarIsoMsZulu() {
>     final String dateTime = "2009-10-16T16:42:16.000Z";
>     GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT-8"));
>     cal.clear();
>     cal.set(2009, 9, 16, 8, 42, 16);
>     cal.getTime();
>     FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
TimeZone.getTimeZone("GMT"));
>     assertEquals("dateTime", dateTime, format.format(cal));
>   }
> {noformat}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message