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

DateTimeFormatterBuilder's appendInstant() method should parse any offset provided in the input

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 12
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Hide
      There is no change in the formatting behavior. During parsing, an optional numeric offset will now be accepted.
      Show
      There is no change in the formatting behavior. During parsing, an optional numeric offset will now be accepted.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Add support for DateTimeFormatterBuilder.appendInstant() to parse offset provided in the input.

      Problem

      DateTimeFormatter.ISO_INSTANT(using the DateTimeFormatterBuilder.appendInstant() internally) could parse only the input text of the format "2018-10-01T16:45:51Z" . The support for parsing date-time of the format "2018-10-01T16:45:51+00:00" was not available even though both of them are valid formats as per ISO-8601.

      Solution

      During parsing, a format containing no offset (using appendLiteral('Z')) was used to parse the input text to an Instant. The format should be modified to use the behavior of existing DateTimeFormatterBuilder.appendOffsetId() method to parse any offset in the input text or use the 'Z' literal in case of zero or no offset. The specification should be modified accordingly.

      Specification

      • Changing DateTimeFormatter.ISO_INSTANT

      from

       * When formatting, the second-of-minute is always output.
       * The nano-of-second outputs zero, three, six or nine digits as necessary.
       * When parsing, time to at least the seconds field is required.

      to

      * When formatting, the instant will always be suffixed by 'Z' to indicate UTC.
      * The second-of-minute is always output.
      * The nano-of-second outputs zero, three, six or nine digits as necessary.
      * When parsing, the behaviour of {@link DateTimeFormatterBuilder#appendOffsetId()}
      * will be used to parse the offset, converting the instant to UTC as necessary.
      * The time to at least the seconds field is required.
      • Changing appendInstant() of DateTimeFormatterBuilder class

      from

      * {@link DateTimeFormatter#parsedLeapSecond()} for full details.
      * <p>
      * An alternative to this method is to format/parse the instant as a single
      * epoch-seconds value. That is achieved using {@code appendValue(INSTANT_SECONDS)}.
      *

      to

       * {@link DateTimeFormatter#parsedLeapSecond()} for full details.
       * <p>
       * When formatting, the instant will always be suffixed by 'Z' to indicate UTC.
       * When parsing, the behaviour of {@link DateTimeFormatterBuilder#appendOffsetId()}
       * will be used to parse the offset, converting the instant to UTC as necessary.
       * <p>
       * An alternative to this method is to format/parse the instant as a single
       * epoch-seconds value. That is achieved using {@code appendValue(INSTANT_SECONDS)}.
       *

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psonal Pallavi Sonal
                Reporter:
                webbuggrp Webbug Group
                Reviewed By:
                Naoto Sato, Roger Riggs
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: