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

CustomTzIDCheckDST.java may fail at future date

    XMLWordPrintable

Details

    Backports

      Description

        test/jdk/java/util/TimeZone/CustomTzIDCheckDST.java may fail at future date.
        I created small testcase (CheckDST.java) from CustomTzIDCheckDST.java
        $ cat CheckDST.java
        import java.util.Calendar;
        import java.util.Date;
        import java.util.SimpleTimeZone;

        public class CheckDST {
            private static String CUSTOM_TZ = "MEZ-1MESZ,M3.5.0,M10.5.0";
            public static void main(String args[]) throws Throwable {
                runTZTest();
            }

            /* TZ code will always be set to "MEZ-1MESZ,M3.5.0,M10.5.0".
             * This ensures the transition periods for Daylights Savings should be at March's last
             * Sunday and October's last Sunday.
             */
            private static void runTZTest() {
                Date time = new Date();
                if (new SimpleTimeZone(3600000, "MEZ-1MESZ", Calendar.MARCH, -1, Calendar.SUNDAY, 0,
                        Calendar.OCTOBER, -1, Calendar.SUNDAY, 0).inDaylightTime(time)) {
                    // We are in Daylight savings period.
                    if (time.toString().endsWith("GMT+02:00 " + Integer.toString(time.getYear() + 1900)))
                        return;
                } else {
                    if (time.toString().endsWith("GMT+01:00 " + Integer.toString(time.getYear() + 1900)))
                        return;
                }

                // Reaching here means time zone did not match up as expected.
                throw new RuntimeException("Got unexpected timezone information: " + time);
            }
        }

        I tested CheckDST with faketime, then I got following results
        $ TZ=GMT faketime -m "2023-03-25 22:59:59" env TZ="MEZ-1MESZ,M3.5.0,M10.5.0" $HOME/jdk-21-b02/bin/java CheckDST
        $ TZ=GMT faketime -m "2023-03-25 23:00:00" env TZ="MEZ-1MESZ,M3.5.0,M10.5.0" $HOME/jdk-21-b02/bin/java CheckDST
        Exception in thread "main" java.lang.RuntimeException: Got unexpected timezone information: Sun Mar 26 00:00:00 GMT+01:00 2023
                at CheckDST.runTZTest(CheckDST.java:28)
                at CheckDST.main(CheckDST.java:8)

        Attachments

          Issue Links

            Activity

              People

                itakiguchi Ichiroh Takiguchi
                itakiguchi Ichiroh Takiguchi
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: