-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8288377: [REDO] DST not applying properly with zone id offset set with TZ env variable #9312
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
Conversation
8288377: Offset calculation fix for DST with custom TZ.
|
👋 Welcome back Deigue! A progress list of the required criteria for merging this PR into |
Webrevs
|
|
I just wonder we could simply call |
|
@naotoj Thanks for letting me know, hadn't tried that function yet. At first look it seems to working exactly as needed, but I will need to parse the result into substrings to put a semi-colon between the hour and minute offset, in order to match the output required. But definitely looks much simpler in comparison ... |
|
I think you could simplify the code further, i.e. there will be no need to separate the function with |
|
I have simplified the implementation and tested that it works on Linux ... I still need to check this on a MAC OS computer and see if it working like before without any issues. One more thing to note/I'd like to make sure is what the output looks like when TZ is GMT. Want to ensure that the final string being passed down is just "GMT" and that |
| } | ||
|
|
||
| #else | ||
| strftime(offset, 6, "%z", &localtm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return value has to be examined. If it is not 5, then I'd expect falling back to "GMT".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added check to verify output is as expected before proceeding, with fallback
| } | ||
| sprintf(buf, (const char *)"GMT%c%02d:%02d", | ||
| sign, (int)(offset/3600), (int)((offset%3600)/60)); | ||
| sprintf(buf, (const char *)"GMT%s", gmt_offset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use the format string as "GMT%c%c%c:%c%c" so that the extra gmt_offset variable can be eliminated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted, forgot that the final string returned was able to be formatted itself as well.
You could compare GMT's hour/miute with localtime's. If they are identical, then return "GMT". For that, we may end up reviving |
naotoj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Looks good with one minor request.
| offset = -offset; | ||
| sign = '+'; | ||
| strftime(offset, 6, "%z", &localtm); | ||
| if (strlen(offset) != 5) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant was the return value from strftime, not the length from strlen, ie, if (strftime(...) != 5). It should be more robust.
naotoj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
|
@Deigue 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: 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 1271 new commits pushed to the
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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@naotoj) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
/integrate |
|
/sponsor |
|
Going to push as commit 3c32564.
Your commit was automatically rebased without conflicts. |
This is a REDO of the Fix that was incompletely implemented earlier:
8285838: Fix for TZ environment variable DST rules
Offset calculation now accounts all the way upto year in order to avoid cross-day miscalculations as well as to calculate always in the correct direction for offset. In situations where there may be multiple days, the excess days of offset will be shaved off by applying mod to
seconds_per_day, which will remove the excessive days that might be included in the offset calculation for special scenarios like a leap year / February months and variances between 30 and 31 days.I have tested this solution with the cases where this fix had failed last time as well, and confirmed it works:

(where 7200 represents 7200 seconds -> +2 hour offset)
Sample output:
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9312/head:pull/9312$ git checkout pull/9312Update a local copy of the PR:
$ git checkout pull/9312$ git pull https://git.openjdk.org/jdk pull/9312/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9312View PR using the GUI difftool:
$ git pr show -t 9312Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9312.diff