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

Calendar.add broken at DST onset

XMLWordPrintable

    • 1.2beta4
    • generic, sparc
    • generic, solaris_2.6
    • Not verified



      Name: bb33257 Date: 02/23/98


      Calendar.add(Calendar.HOUR, 1) doesn't work at DST onset.

      The problem is that the time is incremented, but GregorianCalendar
      is too clever and tries to adjust the time back for the DST shift.

      The same problem will occur at the DST cessation and also with
      other units of adding.

      void test() {
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("PST"));
        cal.setTime(new Date(98, Calendar.APRIL, 5, 1, 0));
        Date before = cal.getTime();
        cal.add(Calendar.HOUR, 1);
        Date after = cal.getTime();
        if (before.equals(after)) throw new Exception("FAIL");
      }
      ======================================================================

            aliusunw Alan Liu (Inactive)
            bcbeck Brian Beck (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: