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

Calendar.setTimeZone() doesn't update all fields

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.1.4, 1.1.6, 1.2.0
    • Fix Version/s: 1.3.0
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      generic, x86
    • OS:
      generic, solaris_2.6, windows_95

      Description



      Name: nl37777 Date: 09/29/98


      The Calendar.setTimeZone does not update all of
      the fields in the Calendar object.

      Notice in the output below that when a Calendar
      created with a PST timezone is converted to the
      EST timezone, the ERA,YEAR,MONTH,WEEK_OF_YEAR,
      WEEK_OF_MONTH,DAY_OF_MONTH,DAY_OF_YEAR,DAY_OF_WEEK,
      DAY_OF_WEEK_IN_MONTH,AM_PM,HOUR,HOUR_OF_DAY,MINUTE,
      SECOND,MILLISECOND,ZONE_OFFSET and DST_OFFSET
      values are not updated.

      This causes the Calendar.get(field) to return the
      incorrect values

      Here's a sample program to illustrate the bug.

      import java.io.*;
      import java.util.*;


      public class datebug
      {

        public static void main(String argv[])
        {
          Calendar caltmp = Calendar.getInstance();
          Calendar calEST = Calendar.getInstance(TimeZone.getTimeZone("EST"));
          Calendar calPST = Calendar.getInstance(TimeZone.getTimeZone("PST"));

          caltmp.set(1998,8,28,23,0,0); // Set the time

          Date date = caltmp.getTime(); // Create a date object

          System.out.println("Date : " + date);

          calEST.setTime(date);
          calPST.setTime(date);

          System.out.println("calEST Date : " + calEST.getTime() );
          System.out.println("calPST Date : " + calPST.getTime() );

          System.out.println("\ncalEST Calendar");
          System.out.println(calEST);

          System.out.println("\ncalPST Calendar");
          System.out.println(calPST);

          System.out.println("\nConvert PST to EST");

          calPST.setTimeZone(TimeZone.getTimeZone("EST"));

          System.out.println("\ncalPST Date : " + calPST.getTime());

          System.out.println("\ncalPST Calendar in EST");
          System.out.println(calPST);

        }
      }

      Here is the output from the above program :

      Date : Mon Sep 28 23:00:00 EDT 1998
      calEST Date : Mon Sep 28 23:00:00 EDT 1998
      calPST Date : Mon Sep 28 23:00:00 EDT 1998

      calEST Calendar
      java.util.GregorianCalendar[time=907038000558,areFieldsSet=true,areAllFieldsSet=true,
      lenient=true,zone=java.util.SimpleTimeZone[id=EST,offset=-18000000,dstSavings=3600000,
      useDaylight=true,startYear=0,startMode=3,startMonth=3,startDay=1,startDayOfWeek=1,
      startTime=7200000,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000],
      firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1998,MONTH=8,WEEK_OF_YEAR=40,
      WEEK_OF_MONTH=5,DAY_OF_MONTH=28,DAY_OF_YEAR=271,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=4,
      AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=0,SECOND=0,MILLISECOND=558,ZONE_OFFSET=-18000000,
      DST_OFFSET=3600000]

      calPST Calendar
      java.util.GregorianCalendar[time=907038000558,areFieldsSet=true,areAllFieldsSet=true,
      lenient=true,zone=java.util.SimpleTimeZone[id=PST,offset=-28800000,dstSavings=3600000,
      useDaylight=true,startYear=0,startMode=3,startMonth=3,startDay=1,startDayOfWeek=1,
      startTime=7200000,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000],
      firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1998,MONTH=8,WEEK_OF_YEAR=40,
      WEEK_OF_MONTH=5,DAY_OF_MONTH=28,DAY_OF_YEAR=271,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=4,
      AM_PM=1,HOUR=8,HOUR_OF_DAY=20,MINUTE=0,SECOND=0,MILLISECOND=558,ZONE_OFFSET=-28800000,
      DST_OFFSET=3600000]

      Convert PST to EST

      calPST Date : Mon Sep 28 23:00:00 EDT 1998

      calPST Calendar in EST
      java.util.GregorianCalendar[time=907038000558,areFieldsSet=true,areAllFieldsSet=true,
      lenient=true,zone=java.util.SimpleTimeZone[id=EST,offset=-18000000,dstSavings=3600000,
      useDaylight=true,startYear=0,startMode=3,startMonth=3,startDay=1,startDayOfWeek=1,
      startTime=7200000,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000],
      firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1998,MONTH=8,WEEK_OF_YEAR=40,
      WEEK_OF_MONTH=5,DAY_OF_MONTH=28,DAY_OF_YEAR=271,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=4,
      AM_PM=1,HOUR=8,HOUR_OF_DAY=20,MINUTE=0,SECOND=0,MILLISECOND=558,ZONE_OFFSET=-28800000,
      DST_OFFSET=3600000]
      (Review ID: 37904)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                aliusunw Alan Liu (Inactive)
                Reporter:
                nlindenbsunw Norbert Lindenberg (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: