You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Christian P. MOMON (JIRA)" <ji...@apache.org> on 2013/09/13 03:18:52 UTC
[jira] [Commented] (LANG-538) DateFormatUtils.format does not
correctly change Calendar TimeZone in certain situations
[ https://issues.apache.org/jira/browse/LANG-538?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13766132#comment-13766132 ]
Christian P. MOMON commented on LANG-538:
-----------------------------------------
Hi. This bug is existing in version 3.3.1. The "assertEquals("dateTime", dateTime, format.format(cal));" from the test above returns the following error:
org.junit.ComparisonFailure: dateTime expected:<2009-10-16T[16]:42:16.000Z> but was:<2009-10-16T[08]:42:16.000Z>
Reproduced whit Sun Java version: 1.6.0_45 and 1.7.0_21 on Fedora 17 (Linux 3.9.10-100.fc17.i686.PAE).
I will try to clone this issue.
> 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: 2.5
>
>
> 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.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira