--- old/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java 2018-09-19 14:14:07.477585800 +0530 +++ new/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java 2018-09-19 14:14:05.802592800 +0530 @@ -647,12 +647,12 @@ appendInternal(pp.withFixedWidth()); // Retain the previous active parser active.valueParserIndex = activeValueParser; - } else { + } else { // Modify the active parser to be fixed width basePP = basePP.withFixedWidth(); // The new parser becomes the mew active parser active.valueParserIndex = appendInternal(pp); - } + } // Replace the modified parser with the updated one active.printerParsers.set(activeValueParser, basePP); } else { @@ -3456,14 +3456,27 @@ // new context to avoid overwriting fields like year/month/day int minDigits = (fractionalDigits < 0 ? 0 : fractionalDigits); int maxDigits = (fractionalDigits < 0 ? 9 : fractionalDigits); - CompositePrinterParser parser = new DateTimeFormatterBuilder() + boolean offsetPresent = false; + int length = text.length(); + String pattern = "+HH:mm"; + String noOffsetText = "0"; + if((text.charAt(length - 3) == '+' && text.subSequence(length - 3, length).toString().equals("+00")) + || (text.charAt(length - 5) == '+' && text.subSequence(length - 5, length).toString().equals("+0000")) + || (text.charAt(length - 6) == '+' && text.subSequence(length - 6, length).toString().equals("+00:00"))) { + offsetPresent = true; + if(text.charAt(length - 5) == '+') { + pattern = "+HHmm"; + } + } + DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder() .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); + .appendFraction(NANO_OF_SECOND, minDigits, maxDigits, true); + + builder = (offsetPresent) ? builder.appendOffset(pattern, noOffsetText) : builder.appendLiteral('Z'); + CompositePrinterParser parser = builder.toFormatter().toPrinterParser(false); DateTimeParseContext newContext = context.copy(); int pos = parser.parse(newContext, text, position); if (pos < 0) {