JDK-8288377 : [REDO] DST not applying properly with zone id offset set with TZ env variable
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 18
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2022-06-14
  • Updated: 2023-10-27
  • Resolved: 2022-08-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 19 JDK 20
11.0.18Fixed 17.0.10-oracleFixed 19.0.2Fixed 20 b10Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8288378 :  
Description
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
Comments
Fix Request (19u, 17u, 11u) on behalf of Gaurav Chaudhari (GitHub user Deigue) Requesting this fix to be backported in order to address JDK-8288377, which fixes the incorrect timezone displayed in DST period, when a custom TZ code is used. The risk is minimal as the code change is only a small piece of logic in how the offset between GMT and local time is calculated and returned. (offset fix) In addition, the repeat definition of the function for macOS has been consolidated, while keeping the macOS specific logic when it is needed. Tier 1 testing is passing on macOS and Linux. Patch applies cleanly in 19 and 17, needed a small modification in 11.
22-09-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/662 Date: 2022-09-08 19:58:33 +0000
08-09-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk19u/pull/16 Date: 2022-09-01 20:55:48 +0000
01-09-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/1328 Date: 2022-08-15 19:49:14 +0000
15-08-2022

Changeset: 3c325641 Author: Gaurav Chaudhari <deigue@hotmail.com> Committer: Naoto Sato <naoto@openjdk.org> Date: 2022-08-04 18:49:05 +0000 URL: https://git.openjdk.org/jdk/commit/3c3256414f7df049cdd6c8519fbcea0d818a1a33
04-08-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/9312 Date: 2022-06-28 18:52:32 +0000
28-06-2022

Offset should fall within -12 to +14. The previous fix needs to be adjusted to meet the requirement. Here is the quote from the `java.time.ZoneOffset` class: ``` In 2008, time-zone offsets around the world extended from -12:00 to +14:00. To prevent any problems with that range being extended, yet still provide validation, the range of offsets is restricted to -18:00 to 18:00 inclusive. ```
14-06-2022