Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8299194: CustomTzIDCheckDST.java may fail at future date #11756

Closed
wants to merge 2 commits into from

Conversation

takiguc
Copy link

@takiguc takiguc commented Dec 21, 2022

test/jdk/java/util/TimeZone/CustomTzIDCheckDST.java may fail at future date.
I used following standalone testcase

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)

I assume TZ=MEZ-1MESZrefers Europe/Berlin timezone.
In this case, TZ environment variable should be MEZ-1MESZ,M3.5.0,M10.5.0/3 (/3 is missing in testcase)

CustomTzIDCheckDST should run with daylight saving time.
Add Simulate Southern Hemisphere by MEZ-1MESZ,M10.5.0,M3.5.0/3

Tested by standalone testcase

$ cat CheckDST1.java
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import java.time.DayOfWeek;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAdjusters;
public class CheckDST1 {
    // Northern Hemisphere
    private static String CUSTOM_TZ = "MEZ-1MESZ,M3.5.0,M10.5.0/3";
    // Simulate Southern Hemisphere
    private static String CUSTOM_TZ2 = "MEZ-1MESZ,M10.5.0,M3.5.0/3";
    public static void main(String args[]) throws Throwable {
        runTZTest();
    }

    /* TZ code will always be set to "MEZ-1MESZ,M3.5.0,M10.5.0/3".
     * 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();
        String tzStr = System.getenv("TZ");
        if (tzStr == null)
            throw new RuntimeException("Got unexpected timezone information: TZ is null");
        boolean nor = tzStr.matches(".*,M3\\..*,M10\\..*");
        TimeZone tz = new SimpleTimeZone(3600000, tzStr,
            nor ? Calendar.MARCH : Calendar.OCTOBER, -1,
            Calendar.SUNDAY, 3600000, SimpleTimeZone.UTC_TIME,
            nor ? Calendar.OCTOBER : Calendar.MARCH, -1,
            Calendar.SUNDAY, 3600000, SimpleTimeZone.UTC_TIME,
            3600000);
        System.out.println(time);
        if (tz.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: " + tzStr + " " + time);
    }

    private static ZonedDateTime getLastSundayOfMonth(ZonedDateTime date) {
        return date.with(TemporalAdjusters.lastInMonth(DayOfWeek.SUNDAY));
    }
}

Check Europe/Berlin timezone settings

$ zdump -v Europe/Berlin | grep 2023
Europe/Berlin  Sun Mar 26 00:59:59 2023 UTC = Sun Mar 26 01:59:59 2023 CET isdst=0 gmtoff=3600
Europe/Berlin  Sun Mar 26 01:00:00 2023 UTC = Sun Mar 26 03:00:00 2023 CEST isdst=1 gmtoff=7200
Europe/Berlin  Sun Oct 29 00:59:59 2023 UTC = Sun Oct 29 02:59:59 2023 CEST isdst=1 gmtoff=7200
Europe/Berlin  Sun Oct 29 01:00:00 2023 UTC = Sun Oct 29 02:00:00 2023 CET isdst=0 gmtoff=3600

Test results are as follows:

Northern Hemisphere side

$ TZ=GMT faketime -m '2023-03-26 00:59:59' env TZ=MEZ-1MESZ,M3.5.0,M10.5.0/3 date
Sun Mar 26 01:59:59 MEZ 2023
$ TZ=GMT faketime -m '2023-03-26 00:59:59' env TZ=MEZ-1MESZ,M3.5.0,M10.5.0/3 java CheckDST1
Sun Mar 26 01:59:59 GMT+01:00 2023

$ TZ=GMT faketime -m '2023-03-26 01:00:00' env TZ=MEZ-1MESZ,M3.5.0,M10.5.0/3 date
Sun Mar 26 03:00:00 MESZ 2023
$ TZ=GMT faketime -m '2023-03-26 01:00:00' env TZ=MEZ-1MESZ,M3.5.0,M10.5.0/3 java CheckDST1
Sun Mar 26 03:00:00 GMT+02:00 2023

$ TZ=GMT faketime -m '2023-10-29 00:59:59' env TZ=MEZ-1MESZ,M3.5.0,M10.5.0/3 date
Sun Oct 29 02:59:59 MESZ 2023
$ TZ=GMT faketime -m '2023-10-29 00:59:59' env TZ=MEZ-1MESZ,M3.5.0,M10.5.0/3 java CheckDST1
Sun Oct 29 02:59:59 GMT+02:00 2023

$ TZ=GMT faketime -m '2023-10-29 01:00:00' env TZ=MEZ-1MESZ,M3.5.0,M10.5.0/3 date
Sun Oct 29 02:00:00 MEZ 2023
$ TZ=GMT faketime -m '2023-10-29 01:00:00' env TZ=MEZ-1MESZ,M3.5.0,M10.5.0/3 java CheckDST1
Sun Oct 29 02:00:00 GMT+01:00 2023

Southern Hemisphere side

$ TZ=GMT faketime -m '2023-03-26 00:59:59' env TZ=MEZ-1MESZ,M10.5.0,M3.5.0/3 date
Sun Mar 26 02:59:59 MESZ 2023
$bTZ=GMT faketime -m '2023-03-26 00:59:59' env TZ=MEZ-1MESZ,M10.5.0,M3.5.0/3 java CheckDST1
Sun Mar 26 02:59:59 GMT+02:00 2023

$ TZ=GMT faketime -m '2023-03-26 01:00:00' env TZ=MEZ-1MESZ,M10.5.0,M3.5.0/3 date
Sun Mar 26 02:00:00 MEZ 2023
$ TZ=GMT faketime -m '2023-03-26 01:00:00' env TZ=MEZ-1MESZ,M10.5.0,M3.5.0/3 java CheckDST1
Sun Mar 26 02:00:00 GMT+01:00 2023

$ TZ=GMT faketime -m '2023-10-29 00:59:59' env TZ=MEZ-1MESZ,M10.5.0,M3.5.0/3 date
Sun Oct 29 01:59:59 MEZ 2023
$ TZ=GMT faketime -m '2023-10-29 00:59:59' env TZ=MEZ-1MESZ,M10.5.0,M3.5.0/3 java CheckDST1
Sun Oct 29 01:59:59 GMT+01:00 2023

$ TZ=GMT faketime -m '2023-10-29 01:00:00' env TZ=MEZ-1MESZ,M10.5.0,M3.5.0/3 date
Sun Oct 29 03:00:00 MESZ 2023
$ TZ=GMT faketime -m '2023-10-29 01:00:00' env TZ=MEZ-1MESZ,M10.5.0,M3.5.0/3 java CheckDST1
Sun Oct 29 03:00:00 GMT+02:00 2023

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8299194: CustomTzIDCheckDST.java may fail at future date

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/11756/head:pull/11756
$ git checkout pull/11756

Update a local copy of the PR:
$ git checkout pull/11756
$ git pull https://git.openjdk.org/jdk pull/11756/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11756

View PR using the GUI difftool:
$ git pr show -t 11756

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/11756.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 21, 2022

👋 Welcome back itakiguchi! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot changed the title 8299194: CustomTzIDCheckDST.java may fail at future date 8299194: CustomTzIDCheckDST.java may fail at future date Dec 21, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 21, 2022
@openjdk
Copy link

openjdk bot commented Dec 21, 2022

@takiguc The following labels will be automatically applied to this pull request:

  • core-libs
  • i18n

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Dec 21, 2022
@mlbridge
Copy link

mlbridge bot commented Dec 21, 2022

Webrevs

Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Looks good overall. A couple of minor comments/questions.

} else {
runTZTest();
}
}

/* TZ code will always be set to "MEZ-1MESZ,M3.5.0,M10.5.0".
/* TZ code will always be set to "MEZ-1MESZ,M3.5.0,M10.5.0/3".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably adding "northern hemisphere" is helpful here.

String tzStr = System.getenv("TZ");
if (tzStr == null)
throw new RuntimeException("Got unexpected timezone information: TZ is null");
boolean nor = tzStr.matches(".*,M3\\..*,M10\\..*");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use RegEx? A simple comparison with CUSTOM_TZ does not work?

@takiguc
Copy link
Author

takiguc commented Dec 21, 2022

Thanks @naotoj .
I appreciate you suggestion.
Please review it again.

Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@openjdk
Copy link

openjdk bot commented Dec 22, 2022

@takiguc This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8299194: CustomTzIDCheckDST.java may fail at future date

Reviewed-by: naoto

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 15 new commits pushed to the master branch:

  • a3693cc: 8295087: Manual Test to Automated Test Conversion
  • 5012039: 8298887: On the latest macOS+XCode the Robot API may report wrong colors
  • 34cdda5: Merge
  • 22007a1: 8298893: Rename option UsePolyIntrinsics to UsePoly1305Intrinsics
  • 9adc349: 8298726: (fs) Change PollingWatchService to record last modified time as FileTime rather than milliseconds
  • 81933b7: 8298642: ParallelGC -XX:+UseNUMA eden spaces allocated on wrong node
  • 92fe304: 8298588: WebSockets: HandshakeUrlEncodingTest unnecessarily depends on a response body
  • f7be5b5: 8299156: Broken link in jdk.compiler/module-info.java
  • 3d4d9fd: 8298947: compiler/codecache/MHIntrinsicAllocFailureTest.java fails intermittently
  • e85d00f: 8299147: Minor accessibility errors in the specs and man index pages
  • ... and 5 more: https://git.openjdk.org/jdk/compare/a7d6de71bb83c8715654f61dd166aad6e8dab847...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 22, 2022
@takiguc
Copy link
Author

takiguc commented Dec 22, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Dec 22, 2022

Going to push as commit 5e2de89.
Since your change was applied there have been 18 commits pushed to the master branch:

  • 6ccee83: 8292206: TestCgroupMetrics.java fails as getMemoryUsage() is lower than expected
  • b378381: 8299199: Avoid redundant split calls in FontConfiguration.initReorderMap implementations
  • 62a033e: 8299191: Unnecessarily global friend functions for relocInfo
  • a3693cc: 8295087: Manual Test to Automated Test Conversion
  • 5012039: 8298887: On the latest macOS+XCode the Robot API may report wrong colors
  • 34cdda5: Merge
  • 22007a1: 8298893: Rename option UsePolyIntrinsics to UsePoly1305Intrinsics
  • 9adc349: 8298726: (fs) Change PollingWatchService to record last modified time as FileTime rather than milliseconds
  • 81933b7: 8298642: ParallelGC -XX:+UseNUMA eden spaces allocated on wrong node
  • 92fe304: 8298588: WebSockets: HandshakeUrlEncodingTest unnecessarily depends on a response body
  • ... and 8 more: https://git.openjdk.org/jdk/compare/a7d6de71bb83c8715654f61dd166aad6e8dab847...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 22, 2022
@openjdk openjdk bot closed this Dec 22, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 22, 2022
@openjdk
Copy link

openjdk bot commented Dec 22, 2022

@takiguc Pushed as commit 5e2de89.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants