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

ZonedDateTime.parse() returns wrong ZoneOffset around DST fall transition

XMLWordPrintable

    • b100
    • x86_64
    • windows_7

        FULL PRODUCT VERSION :
        java version "1.8.0_20"
        Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
        Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        A DESCRIPTION OF THE PROBLEM :
        Parsing a string with ZonedDateTime.parse() that contains zone offset and zone ID "Europe/Berlin" returns a wrong ZonedDateAndTime (different offset). This error starts exactly at the transition time (included) and ends one hour later (excluded).


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. create a ZonedDateTime with date/time of the DST transition in fall and a ZoneId different from UTC (e.g. "Europe/Berlin")
        2. apply ZonedDateTime.format() with ISO_ZONED_DATE_TIME formatter
        3. apply ZonedDateTime.parse() to the formatted string with same formatter
        4. compare the result to the starting value

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The parsed string should represent the same instant on the time line.
        ACTUAL -
        Starting at the fall DST transition time (included) and ending one hour later (excluded) the offset is one hour too high. Lies 2..5 show wrong result, 1st and last line are correct.

        2012-10-28T02:45:00+02:00[Europe/Berlin] -> 2012-10-28T02:45+02:00[Europe/Berlin]
        2012-10-28T02:00:00+01:00[Europe/Berlin] -> 2012-10-28T02:00+02:00[Europe/Berlin]
        2012-10-28T02:15:00+01:00[Europe/Berlin] -> 2012-10-28T02:15+02:00[Europe/Berlin]
        2012-10-28T02:30:00+01:00[Europe/Berlin] -> 2012-10-28T02:30+02:00[Europe/Berlin]
        2012-10-28T02:45:00+01:00[Europe/Berlin] -> 2012-10-28T02:45+02:00[Europe/Berlin]
        2012-10-28T03:00:00+01:00[Europe/Berlin] -> 2012-10-28T03:00+01:00[Europe/Berlin]


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.time.ZoneId;
        import java.time.ZonedDateTime;
        import java.time.format.DateTimeFormatter;
        import java.time.temporal.ChronoUnit;

        public class LocalDateTimeIssue {
          public static void main(String[] args) {
            ZonedDateTime zdt = ZonedDateTime.of(2012, 10, 28, 2, 45, 0, 0, ZoneId.of("Europe/Berlin"));
            DateTimeFormatter fmt = DateTimeFormatter.ISO_ZONED_DATE_TIME;
            for (int i = 0; i < 6; i++) {
              String s = zdt.format(fmt);
              System.out.println(s + " -> " + ZonedDateTime.parse(s, fmt));
              zdt = zdt.plus(15, ChronoUnit.MINUTES);
            }
          }
        }

        ---------- END SOURCE ----------

              rpatil Ramanand Patil (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: