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)}.
*
- csr of
-
JDK-8166138 DateTimeFormatter.ISO_INSTANT should handle offsets
-
- Resolved
-