RFR: 8364752: Class java.time.Instant cannot parse all ISO 8601 date formats [v5]

Roger Riggs rriggs at openjdk.org
Mon Aug 18 22:31:50 UTC 2025


On Mon, 18 Aug 2025 19:17:02 GMT, Naoto Sato <naoto at openjdk.org> wrote:

>> src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java line 3893:
>> 
>>> 3891:                     .appendFraction(NANO_OF_SECOND, minDigits, maxDigits, true)
>>> 3892:                     .parseLenient()
>>> 3893:                     .appendOffset("+HH", "Z")
>> 
>> The "+HH" pattern is supposed to be ignoring minutes and seconds but it does not appear to.  In jshell, I see:
>> 
>> jshell> Instant.parse("2017-01-01T00:00:00.000-02:10:12")
>> $8 ==> 2017-01-01T02:10:12Z
>> 
>> It would be more consistent with the original pattern to use `"+HH:mm:ss"`
>
> IIUC, "ignoring minutes and seconds" refers to formatting, i.e, "-02:10:12" only prints "-02" Parsing offsets in lenient mode always parses minute/seconds.

True, but you have to read further into the `appendOffset` prose to know that the minutes and sections can be present. Using the full pattern would convey more quickly the full syntax being parsed.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26708#discussion_r2283632033


More information about the core-libs-dev mailing list