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

No DST offset recognized in class Calendar when specified in TZ env var

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • core-libs



      Name: nt126004 Date: 06/17/2002


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

      and

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

      FULL OPERATING SYSTEM VERSION :
      SunOS yellow454.era-a.ericsson.se 5.7 Generic_106541-18
      sun4u sparc SUNW,Ultra-5_10

      A DESCRIPTION OF THE PROBLEM :
      If I set the environment variable TZ to the value
      "EET-2EETDST,89/01:00:00,299/02:00:00" and run the following
      piece of code:

      Calendar rightNow = Calendar.getInstance();
      System.out.println(rightNow.get(Calendar.DST_OFFSET));

      I get the result 0.

      Also, if I run the following piece of code:

      Date time = new Date();
      System.out.println(time.toString());

      I get a result which is one hour before what I get if I type
      "date" on the command line in the same shell.

      If on the other hand, I set TZ to "EET" only, I get the
      result 3600000 from the first piece of code and the result
      of the second piece of code is the same as what I get from
      typing "date" on the command line.

      Conclusion: Java misses the DST information when specified
      manually in TZ environment variable.

      According to bug 4256581 this has been fixed, but the problem is still
      reproducible using jdk 1.4 and jdk 1.3.1 on Solaris 7 and 8.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Set TZ environment variable to
      EET-2EETDST,89/01:00:00,299/02:00:00

      2. Create a program with the following code:
      Calendar rightNow = Calendar.getInstance();
      System.out.println(rightNow.get(Calendar.DST_OFFSET));
      Date time = new Date();
      System.out.println(time.toString());

      3. Check the printouts and compare with the result of typing
      "date" in the shell.

      4. Try the same thing with the TZ environment variable set
      to EET.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      I expected that when TZ was set to
      EET-2EETDST,89/01:00:00,299/02:00:00 the printout of
      Calendar rightNow = Calendar.getInstance();
      System.out.println(rightNow.get(Calendar.DST_OFFSET));
      would be the same (3600000) as when TZ was set to EET (when
      being in the DST interval of course).

      Instead I got 0 and 3600000 respectively.

      Also I expected the printout of
      Date time = new Date();
      System.out.println(time.toString());
      to give the same time as "date" on the command line.

      Instead I got a result being one hour before that of "date".


      This bug can be reproduced always.

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

      public class TZ {
        public static void main(String args[]) {
          Calendar rightNow = Calendar.getInstance();
          System.out.println(rightNow.get(Calendar.DST_OFFSET));
          Date time = new Date();
          System.out.println(time.toString());
        }
      }

      ---------- END SOURCE ----------
      (Review ID: 153404)
      ======================================================================

            okutsu Masayoshi Okutsu
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: