JDK-8183553 : Incorrect ZonedDateTime parsing from String on Daylight saving
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 8u131
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2017-07-04
  • Updated: 2017-07-05
  • Resolved: 2017-07-05
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux Vortex 4.10.0-24-generic #28~16.04.1-Ubuntu SMP Wed Jun 14 11:58:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Conversion from a string to a ZonedDateTime results in incorrect transformation on daylight savings:

String faulty_datetime = "2017-10-29T02:15+01:00[Europe/Rome]";

ZonedDateTime.parse(faulty_datetime).toString() leads to "2017-10-29T02:15+02:00[Europe/Rome]"

Please note the change of timezone

ZonedDateTime.parse(faulty_datetime).plusHours(1).toString() leads to "2017-10-29T02:15+01:00[Europe/Rome]" that is the requested input  date, requires a plus 1 hour

Parsing the string "2017-10-29T02:15+01:00[Europe/Rome]" creates a date 1hr in the past

Please note that all the strings in these examples has been created by actual toString() of ZonedDateTime objects

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Simply try converting to/from the specified datetime

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting to obtain the time i specified in the parsed string, otherwise exchanging dates through strings (on a DB for instance) would be impossible in daylight savings times using java output. My current issue is that after saving a date as a string, when converted back to java object it overlaps with other dates due to the conversion problem

String faulty_datetime = "2017-10-29T02:15+01:00[Europe/Rome]";

ZonedDateTime.parse(faulty_datetime).toString() should lead to  "2017-10-29T02:15+01:00[Europe/Rome]"


ACTUAL -
String faulty_datetime = "2017-10-29T02:15+01:00[Europe/Rome]";

ZonedDateTime.parse(faulty_datetime).toString() leads to  "2017-10-29T02:15+02:00[Europe/Rome]"

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.time.ZonedDateTime;


public class ClientSimulator {

    public static void main(String[] args) throws Exception {

        String faulty_datetime = "2017-10-29T02:15+01:00[Europe/Rome]";
        System.err.println(ZonedDateTime.parse(faulty_datetime).toString().equals(faulty_datetime));
     }
}
---------- END SOURCE ----------


Comments
Closing as duplicate as per the above comment. Backport JDK-8149540 is already open for it.
05-07-2017

This is a real bug. It is a duplicate of https://bugs.openjdk.java.net/browse/JDK-8066982, which has unfortunately not been backported to 8 yet. Could someone at Oracle please volunteer to backport this?
05-07-2017