< prev index next >

src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java

Print this page

        

*** 829,838 **** --- 829,842 ---- * The {@linkplain ResolverStyle resolver style} has no effect on instant parsing. * The end-of-day time of '24:00' is handled as midnight at the start of the following day. * The leap-second time of '23:59:59' is handled to some degree, see * {@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)}. * * @return this, for chaining, not null */
*** 3460,3470 **** .append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T') .appendValue(HOUR_OF_DAY, 2).appendLiteral(':') .appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2) .appendFraction(NANO_OF_SECOND, minDigits, maxDigits, true) ! .appendLiteral('Z') .toFormatter().toPrinterParser(false); DateTimeParseContext newContext = context.copy(); int pos = parser.parse(newContext, text, position); if (pos < 0) { return pos; --- 3464,3474 ---- .append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T') .appendValue(HOUR_OF_DAY, 2).appendLiteral(':') .appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2) .appendFraction(NANO_OF_SECOND, minDigits, maxDigits, true) ! .appendOffsetId() .toFormatter().toPrinterParser(false); DateTimeParseContext newContext = context.copy(); int pos = parser.parse(newContext, text, position); if (pos < 0) { return pos;
*** 3478,3487 **** --- 3482,3492 ---- int min = newContext.getParsed(MINUTE_OF_HOUR).intValue(); Long secVal = newContext.getParsed(SECOND_OF_MINUTE); Long nanoVal = newContext.getParsed(NANO_OF_SECOND); int sec = (secVal != null ? secVal.intValue() : 0); int nano = (nanoVal != null ? nanoVal.intValue() : 0); + int offset = newContext.getParsed(OFFSET_SECONDS).intValue(); int days = 0; if (hour == 24 && min == 0 && sec == 0 && nano == 0) { hour = 0; days = 1; } else if (hour == 23 && min == 59 && sec == 60) {
*** 3490,3500 **** } int year = (int) yearParsed % 10_000; long instantSecs; try { LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days); ! instantSecs = ldt.toEpochSecond(ZoneOffset.UTC); instantSecs += Math.multiplyExact(yearParsed / 10_000L, SECONDS_PER_10000_YEARS); } catch (RuntimeException ex) { return ~position; } int successPos = pos; --- 3495,3505 ---- } int year = (int) yearParsed % 10_000; long instantSecs; try { LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days); ! instantSecs = ldt.toEpochSecond(ZoneOffset.ofTotalSeconds(offset)); instantSecs += Math.multiplyExact(yearParsed / 10_000L, SECONDS_PER_10000_YEARS); } catch (RuntimeException ex) { return ~position; } int successPos = pos;
< prev index next >