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

(tz) GregorianCalendar - Zone Offset for Europe/London different than GMT!

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

      FULL PRODUCT VERSION :
      Tested (and fails) on:

      java version "1.4.1_03"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_03-b02)
      Java HotSpot(TM) Client VM (build 1.4.1_03-b02, mixed mode)

      and

      java version "1.4.2_08"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
      Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)

      and

      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195] (SP 3)
      and
      Microsoft Windows XP [Version 5.1.2600] (SP 2)

      A DESCRIPTION OF THE PROBLEM :
      GregorianCalendar (actually, sun.util.calendar.ZoneInfo) seems to get the time-zone offset wrong when on Windows the 'Automatically Adjust Clock for Daylight Saving Changes' is enabled in Time Zone and the O/S is set up for the GMT time-zone.

      Basically, here in the UK we always use GMT exactly. Only Daylight Savings Time changes here for the summer, where we advance to 1 hour plus GMT; the time-zone always stays exactly the same.

      However, the default time zone obtained from the JVM is Europe/London which appears to have a Time-zone value of 1 Hour plus GMT!

      This is a nasty problem for those who parse times using SimpleDateFormat and then store away the milliseconds result, since it will invariably be wrong!

      As a result, executing the following Java in the Europe/London time-zone:

      System.out.println( new SimpleDateFormat( "yyyyMMddHHmmss" ).parse( "19700101000000" ).getTime() );

      Gives -3600000 instead of 0!

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test case provided.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When the 'Automatically Adjust for Daylight Savings time' flag is disabled or the sample code is run on a JVM that works (1.2.2 and 1.3.1_06 both seem to be OK) you should see the following displayed on the screen:

      Europe/London Zone offset is : 0
      Europe/London DST offset is : 0
      GMT Zone offset is : 0
      GMT DST offset is : 0
      ACTUAL -
      Europe/London Zone offset is : 3600000
      Europe/London DST offset is : 0
      GMT Zone offset is : 0
      GMT DST offset is : 0

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Calendar;
      import java.util.Date;
      import java.util.GregorianCalendar;
      import java.util.TimeZone;

      public class Timetest
      {

          public static void main( String[] args ) throws Exception
          {

              // Show the problem using GregorianCalendar..
              GregorianCalendar cal = new GregorianCalendar();
              cal.setTimeZone( TimeZone.getTimeZone( "Europe/London" ) );
              cal.setTime( new Date( 0 ) );
              System.out.println( cal.getTimeZone().getID() + " Zone offset is : " + cal.get( Calendar.ZONE_OFFSET ) );
              System.out.println( cal.getTimeZone().getID() + " DST offset is : " + cal.get( Calendar.DST_OFFSET ) );

              // On 00:00:00 01-01-1970 in UK, GMT is time-zone, so output should be
              // the same.
              cal.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
              cal.setTime( new Date( 0 ) );
              System.out.println( cal.getTimeZone().getID() + " Zone offset is : " + cal.get( Calendar.ZONE_OFFSET ) );
              System.out.println( cal.getTimeZone().getID() + " DST offset is : " + cal.get( Calendar.DST_OFFSET ) );
           }

      }
      ---------- END SOURCE ----------

            okutsu Masayoshi Okutsu
            okutsu Masayoshi Okutsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: