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

java.util.Calendar fails to properly register setTimeZone()

    Details

      Description



      Name: rm29839 Date: 12/01/97


      import java.util.*;

      /* The following source code brings out the
       * following behavior in java.util.Calendar
       * in both jdk 1.1.3 and 1.1.4.
       *
       * When using the set() routines,
       * Calendar.setTimeZone() fails to re-initialize
       * some state that was created in the
       * first call to setTimeZone() (or the
       * constructor) which specifies the timezone
       * that the wallclock time in the set() calls
       * refer to.
       *
       * Additionally, when using get() calls,
       * setTimeZone() doesn't change the wallclock
       * time retrieved by get().
       */
      class CalBug {
      public static void main (String args[]) {
      TimeZone GMT = TimeZone.getTimeZone("GMT");
      TimeZone PST = TimeZone.getTimeZone("PST");
      int sec = 0, min = 0, hr = 0, day = 1, month = 10, year = 1997;

      Calendar cal1 = new GregorianCalendar(PST);
      cal1.setTime(new Date(880698639000L));
      System.out.println("PST 1 is: " + cal1.get(cal1.HOUR_OF_DAY));
      cal1.setTimeZone(GMT);
      // Issue 1: Changing the timezone doesn't change the
      // represented time.
      System.out.println("GMT 1 is: " + cal1.get(cal1.HOUR_OF_DAY));
      cal1.setTime(new Date(880698639000L));
      System.out.println("GMT 2 is: " + cal1.get(cal1.HOUR_OF_DAY));


      Calendar cal2 = new GregorianCalendar(GMT);
      Calendar cal3 = new GregorianCalendar(PST);

      cal2.set(cal1.get(cal1.YEAR),
      cal1.get(cal1.MONTH),
      cal1.get(cal1.DAY_OF_MONTH),
      cal1.get(cal1.HOUR_OF_DAY),
      cal1.get(cal1.MINUTE),
      cal1.get(cal1.SECOND));

      System.out.println("RGMT 1 is: " + cal2.getTime().getTime());
      cal3.set(year, month, day, hr, min, sec);
      System.out.println("RPST 1 is: " + cal3.getTime().getTime());
      cal3.setTimeZone(GMT);
      System.out.println("RGMT 2 is: " + cal3.getTime().getTime());
      cal2.set(cal1.get(cal1.YEAR),
      cal1.get(cal1.MONTH),
      cal1.get(cal1.DAY_OF_MONTH),
      cal1.get(cal1.HOUR_OF_DAY),
      cal1.get(cal1.MINUTE),
      cal1.get(cal1.SECOND));
      // Issue 2: Calendar continues to use the timezone in its
      // constructor for set() conversions, reguardless
      // of calls to setTimeZone()
      System.out.println("RGMT 3 is: " + cal3.getTime().getTime());
      }
      }
      (Review ID: 21053)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                okutsu Masayoshi Okutsu
                Reporter:
                rmandelsunw Ronan Mandel (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: