Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6670932

(tz) Calender date operations fail on Feb. 29, 2008 (Leap Year)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6
    • core-libs

      FULL PRODUCT VERSION :
      SE Runtime Environment (build 1.6.0_03-b05)
      Java HostSpot Client VM (build 1.6.0_03-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Calling getOffset() on a TimeZone Object, on Feb. 29, causes an java.lang.IllegalArgumentException at sun.util.calendar.ZoneInfo.getOffset(Unknown Source)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Set system date to Feb. 29, 2008
      2) Sample Code:
                  long elasped = (System.currentTimeMillis() - <a time prior to now>
                  elasped = elasped -
                          today.getTimeZone().getOffset(today.ERA,
                          today.get(Calendar.YEAR), today.get(Calendar.MONTH),
                          today.get(Calendar.DATE), today.get(Calendar.DAY_OF_WEEK),
                          0);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It should not fail.
      ACTUAL -
      Results in java.lang.IllegalArgumentException at sun.util.calendar.ZoneInfo.getOffset(Unknown Source)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;
      public class LeapYearDemo {
          public static void main(String[] args) {
              Date aDate = new Date();
              Calendar today = Calendar.getInstance();
              long elasped = (System.currentTimeMillis() - aDate.getTime());
              elasped = elasped -
                      today.getTimeZone().getOffset(today.ERA,
                      today.get(Calendar.YEAR), today.get(Calendar.MONTH),
                      today.get(Calendar.DATE), today.get(Calendar.DAY_OF_WEEK),
                      0);
              System.out.println(elasped);
          }
      ---------- END SOURCE ----------

            okutsu Masayoshi Okutsu
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: