You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2003/12/16 11:44:28 UTC
DO NOT REPLY [Bug 25560] New: -
DateUtils.truncate() is off by one hour when using a date in DST switch 'zone'
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25560>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25560
DateUtils.truncate() is off by one hour when using a date in DST switch 'zone'
Summary: DateUtils.truncate() is off by one hour when using a
date in DST switch 'zone'
Product: Commons
Version: 2.0 Final
Platform: All
OS/Version: All
Status: NEW
Severity: Major
Priority: Other
Component: Lang
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: joachim.hagger@netcetera.ch
Try this using a Central European TimeZone:
import java.util.Calendar;
import org.apache.commons.lang.time.DateUtils;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.MARCH);
cal.set(Calendar.YEAR, 2003);
cal.set(Calendar.DAY_OF_MONTH, 30);
cal.set(Calendar.HOUR_OF_DAY, 5);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
Date date_20030330 = cal.getTime();
Date expDate = DateUtils.truncate(date_20030330, Calendar.DATE);
System.out.println(expDate.toString());
-> Sat Mar 29 23:00:00 MET 2003 instead of Sun Mar 30 00:00:00 MET 2003
If the calendar instance represents a date AFTER the daylight savings time
switch and will be truncated to a time BEFORE the daylight savings time switch,
then the resulting date is wrong. (Daylight savings time was Sun Mar 30 02:00:00
resetting to 01:00.00.) Might also happen when rounding up dates over the
daylight savings time switch...
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org