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

[REDO] DST not applying properly with zone id offset set with TZ env variable

XMLWordPrintable

    • b10
    • Verified

        On behalf of Gaurav Chaudhari:

        When a match cannot be made directly against a recognized region/timezone from the tzdb.dat, TimeZone.getSystemGMTOffsetID() is invoked to find the GMT based offset to calculate the offset and find the corresponding time.
        The native code reached in TimeZone_md.c has a bug for platforms that are not MacOS, where daylight savings is not respected.

        To reproduce the issue:
        TZ="MEZ-1MESZ,M3.5.0,M10.5.0" java -cp . TimeTest
        with the following test , TimeTest.java
        import java.util.Calendar;
        import java.util.TimeZone;
        import java.util.Date;
        import java.text.SimpleDateFormat;


        public class TimeTest {
                public static void main(String args[]) {
                        Date time = Calendar.getInstance().getTime();
                        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSS");

                        System.out.println("Calendar.getInstance().getTime() = "+time);
                        System.out.println("SimpleDateFormat = "+sdf.format(time));
                }
        }

        Reproducible on Linux on Z (s390x) OpenJDK18 (jdk18+38 Temurin)
        TZ="MEZ-1MESZ,M3.5.0,M10.5.0" ~/jdk-18+36/bin/java -cp . TimeTest
        Calendar.getInstance().getTime() = Thu Apr 28 15:55:16 GMT+01:00 2022
        SimpleDateFormat = 28.04.2022 15:55:16.171

        Zone ID can be set according to guidelines below:
        https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html

              tsteele Tyler Steele
              naoto Naoto Sato
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: