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

unix: Calendar.roll is broken on PST timezone

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.3.0
    • core-libs



      Name: dkC103137 Date: 07/05/2000


       Following test shows that Calendar.roll() method returns incorrect result if
      timezone is set using TimeZone.getTimeZone("PST") for calendar object. Test
      fails under Solaris JDK1.3 and Linux JDK1.3. Regression test
      java/util/Calendar/CalendarRegression Test4114578 fails due to this bug.

      Note that if timezone is set using TimeZone.getTimeZone("GMT - 08:00") then test
      passes.

      ---------------------- Test.java -----------------------------
      import java.util.*;
      import java.text.*;

      public class Test {

          public static void main(String[] args) throws Exception {
         
              int ONE_HOUR = 60*60*1000;
              Calendar cal = Calendar.getInstance();
              Date testDate = new Date(99, Calendar.OCTOBER, 25, 1, 0);
              cal.setTimeZone(TimeZone.getTimeZone("PST"));
              //cal.setTimeZone(TimeZone.getTimeZone("GMT - 08:00"));
              cal.setTime(testDate);
              System.out.println("Date before roll - " + cal.getTime().toString());
              cal.roll(Calendar.HOUR, 1);
              long change = cal.getTime().getTime() - testDate.getTime();
              long expectedChange = ONE_HOUR;

              if (change != expectedChange) {
                      System.out.println("Test failed!");
                      System.out.println("actual change - " + change);
                      System.out.println("expected change - " + expectedChange);
                      System.out.println("Date after roll 1 hour - " +
      cal.getTime().toString());
              }
          }
      }
      ------------------------- output -----------------------------
      $ java -version
      java version "1.3.0beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0beta-b09)
      Java HotSpot(TM) Client VM (build 1.3.0beta-b07, mixed mode)
      $ java Test
      Date before roll - Mon Oct 25 01:00:00 GMT+07:00 1999
      Test failed!
      actual change - -39600000
      expected change - 3600000
      Date after roll 1 hour - Sun Oct 24 14:00:00 GMT+07:00 1999
      $
      ------------------------------------------------------------------

      ======================================================================

            okutsu Masayoshi Okutsu
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: