commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <>
Subject [jira] Updated: (LANG-59) [lang] DateUtils.truncate method is buggy when dealing with DST switching hours
Date Sun, 16 Jul 2006 05:20:14 GMT
     [ ]

Niall Pemberton updated LANG-59:

    Attachment: lang_issue_59.txt

The problem seems to be with java.util.Calendar - as soon as it re-calculates the milliseconds
it adjusts the time - even if you set a field without actually changing the value(i.e. set
it to the same value) the same thing happens - it adds an hour to the time (see test case
which demonstrates this).

I'm attaching a pragmatic, but not very elegant solution that works for truncating (and rounding
down) - rather than using the Calendar methods to adjust milliseconds, seconds and minutes
it adjusts the Date's millisecond value directly. Its only fields down to the "hour" level
that affect the date - so truncating milliseconds, seconds and minutes should work fine since
they will still be the same date. Combined with Li Zhang's suggestion of only setting fields
which have changed - this seems to work.

> [lang] DateUtils.truncate method is buggy when dealing with DST switching hours
> -------------------------------------------------------------------------------
>                 Key: LANG-59
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.1
>         Environment: Operating System: Windows XP
> Platform: Other
>            Reporter: Li Zhang
>             Fix For: 2.2
>         Attachments: lang_issue_59.txt
> Try to truncate 2004-10-31 01:00:00 MDT by hour and you'll actually get 2004-10-
> 31 01:00:00 MST, which is one hour after the input hour.
>     // truncate 2004-10-31 01:00:00 MDT
>     Date oct31_01MDT = new Date(1099206000000L);    
>     Date result = DateUtils.truncate(oct31_01MDT, Calendar.HOUR_OF_DAY);
>     assertEquals(oct31_01MDT, result);

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message