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

DateTimeFormatterBuilder zone parsing should recognise DST

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 18
    • 9
    • core-libs
    • None
    • b27

      Given this pattern:

      DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH)

      the appendZoneText(SHORT) method will be called on DateTimeFormatterBuilder. During the DST overlap in Europe/Berlin zone this will print these, one hour apart:

      Sun Oct 30 01:00:00 CEST 2016
      Sun Oct 30 02:00:00 CEST 2016
      Sun Oct 30 02:00:00 CET 2016
      Sun Oct 30 03:00:00 CET 2016

      As can be seen, the text "CEST" or "CET" implies the offset (+02:00 for CEST and +01:00 for CET).

      When parsing, both "CET" and "CEST" are recognised and resolve to ZoneId "Europe/Berlin". But the implied offset is not taken into account. As such, it is not possible to round trip this format, despite all the information being available in the textual form.

      This requires a change to TimeZoneNameUtility.retrieveDisplayNames(), such that it returns not just the display name, but the implied offset (summer time, winter time or generic). When this is used in ZoneTextPrinterParser to find the ZoneId, the extra information (summer/winter/generic) can also be put into DateTimeParserContext. When the context is resolved into a ZonedDateTime/Instant, if the flag is set to summer or winter, the correct offset should be chosen.

      Reference: http://stackoverflow.com/questions/43102957/datetimeformatter-parsing-timezone-names-and-daylight-savings-overlap-times

            naoto Naoto Sato
            scolebourne Stephen Colebourne
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: