<i18n dev> RFR: 8364752: Class java.time.Instant cannot parse all ISO 8601 date formats
Naoto Sato
naoto at openjdk.org
Mon Aug 11 16:42:09 UTC 2025
On Sat, 9 Aug 2025 13:52:45 GMT, ExE Boss <duke at openjdk.org> wrote:
> How about using different patterns for parsing and printing instead?
In fact, the current `DateTimeFormatterBuilder.InstantPrinterParser` already use different behavior for formatting, i.e., only print time in "Z" (no offset).
The following change:
--- a/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java
+++ b/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java
@@ -3887,7 +3887,7 @@ public int parse(DateTimeParseContext context, CharSequence text, int position)
.appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':')
.appendValue(SECOND_OF_MINUTE, 2)
.appendFraction(NANO_OF_SECOND, minDigits, maxDigits, true)
- .appendOffsetId()
+ .appendOffset("+HH:mm:ss", "Z")
.toFormatter().toPrinterParser(false);
DateTimeParseContext newContext = context.copy();
int pos = parser.parse(newContext, text, position);
will parse hour-only offset for `Instant.parse()` but I am not sure we would go for this, as other `ISO` formatters all use "MM" for minutes. @jodastephen any suggestions?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/26708#issuecomment-3175834055
More information about the i18n-dev
mailing list