--- old/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java 2016-02-11 22:53:04.983293001 +0300
+++ new/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java 2016-02-11 22:53:04.693293001 +0300
@@ -866,7 +866,8 @@
* Appends the zone offset, such as '+01:00', to the formatter.
*
* This appends an instruction to format/parse the offset ID to the builder.
- * This is equivalent to calling {@code appendOffset("+HH:MM:ss", "Z")}.
+ * If in lenient parsing mode, this is equivalent to calling {@code appendOffset("+HH:mm:ss", "Z")}.
+ * Otherwise this is equivalent to calling {@code appendOffset("+HH:MM:ss", "Z")}.
*
* @return this, for chaining, not null
*/
@@ -888,7 +889,8 @@
*
* During parsing, the offset is parsed using the format defined below.
* If the offset cannot be parsed then an exception is thrown unless the
- * section of the formatter is optional.
+ * section of the formatter is optional. In lenient parsing mode, the minutes
+ * are optional in the patterns +HHMMss and +HH:MM:ss.
*
* The format of the offset is controlled by a pattern which must be one
* of the following:
@@ -902,6 +904,10 @@
*
{@code +HH:MM:ss} - hour and minute, with second if non-zero, with colon
* {@code +HHMMSS} - hour, minute and second, no colon
* {@code +HH:MM:SS} - hour, minute and second, with colon
+ * {@code +HHmmss} - hour, with minute if non-zero or with minute and
+ * second if non-zero, no colon
+ * {@code +HH:mm:ss} - hour, with minute if non-zero or with minute and
+ * second if non-zero, with colon
*
* The "no offset" text controls what text is printed when the total amount of
* the offset fields to be output is zero.
@@ -3315,7 +3321,7 @@
*/
static final class OffsetIdPrinterParser implements DateTimePrinterParser {
static final String[] PATTERNS = new String[] {
- "+HH", "+HHmm", "+HH:mm", "+HHMM", "+HH:MM", "+HHMMss", "+HH:MM:ss", "+HHMMSS", "+HH:MM:SS",
+ "+HH", "+HHmm", "+HH:mm", "+HHMM", "+HH:MM", "+HHMMss", "+HH:MM:ss", "+HHMMSS", "+HH:MM:SS", "+HHmmss", "+HH:mm:ss",
}; // order used in pattern builder
static final OffsetIdPrinterParser INSTANCE_ID_Z = new OffsetIdPrinterParser("+HH:MM:ss", "Z");
static final OffsetIdPrinterParser INSTANCE_ID_ZERO = new OffsetIdPrinterParser("+HH:MM:ss", "0");
@@ -3362,11 +3368,11 @@
int output = absHours;
buf.append(totalSecs < 0 ? "-" : "+")
.append((char) (absHours / 10 + '0')).append((char) (absHours % 10 + '0'));
- if (type >= 3 || (type >= 1 && absMinutes > 0)) {
+ if ((type >= 3 && type < 9) || (type >= 9 && absSeconds > 0) || (type >= 1 && absMinutes > 0)) {
buf.append((type % 2) == 0 ? ":" : "")
.append((char) (absMinutes / 10 + '0')).append((char) (absMinutes % 10 + '0'));
output += absMinutes;
- if (type >= 7 || (type >= 5 && absSeconds > 0)) {
+ if (type == 7 || type == 8 || (type >= 5 && absSeconds > 0)) {
buf.append((type % 2) == 0 ? ":" : "")
.append((char) (absSeconds / 10 + '0')).append((char) (absSeconds % 10 + '0'));
output += absSeconds;
@@ -3384,6 +3390,12 @@
public int parse(DateTimeParseContext context, CharSequence text, int position) {
int length = text.length();
int noOffsetLen = noOffsetText.length();
+ int parseType = type;
+ if (context.isStrict() == false && type == 6) {
+ parseType = 10;
+ } else if (context.isStrict() == false && type == 5) {
+ parseType = 9;
+ }
if (noOffsetLen == 0) {
if (position == length) {
return context.setParsedField(OFFSET_SECONDS, 0, position, position);
@@ -3404,9 +3416,9 @@
int negative = (sign == '-' ? -1 : 1);
int[] array = new int[4];
array[0] = position + 1;
- if ((parseNumber(array, 1, text, true) ||
- parseNumber(array, 2, text, type >=3) ||
- parseNumber(array, 3, text, false)) == false) {
+ if ((parseNumber(array, 1, text, true, parseType) ||
+ parseNumber(array, 2, text, parseType >= 3 && parseType < 9, parseType) ||
+ parseNumber(array, 3, text, type == 7 || type == 8, parseType)) == false) {
// success
long offsetSecs = negative * (array[1] * 3600L + array[2] * 60L + array[3]);
return context.setParsedField(OFFSET_SECONDS, offsetSecs, position, array[0]);
@@ -3414,7 +3426,7 @@
}
// handle special case of empty no offset text
if (noOffsetLen == 0) {
- return context.setParsedField(OFFSET_SECONDS, 0, position, position + noOffsetLen);
+ return context.setParsedField(OFFSET_SECONDS, 0, position, position);
}
return ~position;
}
@@ -3426,14 +3438,15 @@
* @param arrayIndex the index to parse the value into
* @param parseText the offset ID, not null
* @param required whether this number is required
+ * @param parseType the offset pattern type
* @return true if an error occurred
*/
- private boolean parseNumber(int[] array, int arrayIndex, CharSequence parseText, boolean required) {
- if ((type + 3) / 2 < arrayIndex) {
+ private boolean parseNumber(int[] array, int arrayIndex, CharSequence parseText, boolean required, int parseType) {
+ if ((parseType + 3) / 2 < arrayIndex) {
return false; // ignore seconds/minutes
}
int pos = array[0];
- if ((type % 2) == 0 && arrayIndex > 1) {
+ if ((parseType % 2) == 0 && arrayIndex > 1) {
if (pos + 1 > parseText.length() || parseText.charAt(pos) != ':') {
return required;
}