You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Niall Pemberton (JIRA)" <ji...@apache.org> on 2006/07/16 07:20:14 UTC

[jira] Updated: (LANG-59) [lang] DateUtils.truncate method is buggy when dealing with DST switching hours

     [ http://issues.apache.org/jira/browse/LANG-59?page=all ]

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: http://issues.apache.org/jira/browse/LANG-59
>             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: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org