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

Calendar.set() changes the daylight savings time marker

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.1
    • core-libs



      Name: jl125535 Date: 02/05/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Linux 2.4.9-21enterprise

      ADDITIONAL OPERATING SYSTEMS :
      Windows 2k
      ALL because it is a problem in Calendar.java and its
      subclasses

      A DESCRIPTION OF THE PROBLEM :
      Calling of the set method in Calendar causes the calendar to
      shift from PDT back to PST. See test in Source Code
      section.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the sample code in source code section.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected results:
      date Sun Oct 27 01:00:00 PST 2002
      date Sun Oct 27 01:59:59 PDT 2002
      date Sun Oct 27 01:59:59 PDT 2002

      Actual Results:
      date Sun Oct 27 01:00:00 PST 2002
      date Sun Oct 27 01:59:59 PDT 2002
      date Sun Oct 27 01:00:59 PST 2002


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.math.*;
      import java.net.*;
      import java.text.*;
      import java.util.*;

      public class CalendarBug {
          public static void main(String args[]){
              long DELTA = 1111l;

              Calendar cal = Calendar.getInstance();
              cal.set(2002, Calendar.OCTOBER, 27, 1, 0, 0);
              Date date = cal.getTime();
              System.out.println("date " + date);

              long delta = date.getTime() - DELTA;

              cal.setTimeInMillis(delta);
              date = cal.getTime();
              System.out.println("date " + date);

              // Anyone of the following set() or clear() calls will cause
              // the date to switch from PDT to PST

              cal.set( Calendar.MINUTE, 0 );
      // cal.set( Calendar.SECOND, 0 );
      // cal.set( Calendar.MILLISECOND, 0 );
      // cal.clear( Calendar.MINUTE );
      // cal.clear( Calendar.SECOND );
      // cal.clear( Calendar.MILLISECOND );

              date = cal.getTime();
              System.out.println("date " + date);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Use a set of something like

      cal.set(Calendar.MINUTE, -1 * cal.get(Calendar.MINUTE));
      (Review ID: 166646)
      ======================================================================

            okutsu Masayoshi Okutsu
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: