DateTimeFormatter predefined formatters should support short time zone offsets

XMLWordPrintable

    • Type: CSR
    • Resolution: Approved
    • Priority: P3
    • 27
    • Component/s: core-libs
    • None
    • behavioral
    • low
    • With this change, date/time texts that have hour-only offsets can be parsed with predefined ISO formatters. I don't think this change will cause ill effects on users' code.
    • Java API
    • SE

      Summary

      Predefined ISO 8601 formatters that accept zone offsets should support short zone offsets for parsing

      Problem

      ISO 8601 allows short format offsets that are hour offsets only. JDK-8032051 fixed ZonedDateTime (ISO_OFFSET_DATE_TIME and BASIC_ISO_DATE formatters) to allow short offsets, and JDK-8364752 fixed ISO_INSTANT as well. However, the other predefined ISO formatters that accept zone offsets remain unfixed.

      Solution

      For other ISO formatters, perform lenient parsing for the offsets. This should apply to the following formatters:

      ISO_DATE
      ISO_TIME
      ISO_DATE_TIME
      ISO_OFFSET_DATE
      ISO_OFFSET_TIME
      ISO_ORDINAL_DATE
      ISO_WEEK_DATE
      

      Specification

      Add the following one sentence in the field descriptions of the above formatters in java.time.format.DateTimeFormatter:

             * <li>The {@link ZoneOffset#getId() offset ID}. If the offset has seconds then
             *  they will be handled even though this is not part of the ISO-8601 standard.
      +      *  The offset parsing is lenient, which allows the minutes and seconds to be optional.
             *  Parsing is case insensitive.
      

            Assignee:
            Naoto Sato
            Reporter:
            Martin Buchholz
            Justin Lu, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: