Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-13

[lang] DateUtils.truncate() is off by one hour when using a date in DST switch 'zone'

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0
    • 2.1
    • lang.time.*
    • None
    • Operating System: All
      Platform: All

    • 25560

    Description

      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...

      Attachments

        Activity

          People

            Unassigned Unassigned
            joachim.hagger@netcetera.ch Joachim Hagger
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: