--- a/jdk/src/share/classes/java/time/format/DateTimeFormatterBuilder.java Sat Mar 29 12:29:21 2014 +0400
+++ b/jdk/src/share/classes/java/time/format/DateTimeFormatterBuilder.java Sat Mar 29 15:01:47 2014 -0400
@@ -2596,8 +2596,16 @@
return value;
}
- boolean isFixedWidth() {
- return subsequentWidth == -1;
+ /**
+ * For NumberPrinterParser, the width is fixed depending on the
+ * minWidth, maxWidth, signStyle and whether subsequent fields are fixed.
+ * @param context the context
+ * @return true if the field is fixed width
+ * @see DateTimeFormatterBuilder#appendValue(java.time.temporal.TemporalField, int)
+ */
+ boolean isFixedWidth(DateTimeParseContext context) {
+ return subsequentWidth == -1 ||
+ (subsequentWidth > 0 && minWidth == maxWidth && signStyle == SignStyle.NOT_NEGATIVE);
}
@Override
@@ -2626,12 +2634,12 @@
return ~position;
}
}
- int effMinWidth = (context.isStrict() || isFixedWidth() ? minWidth : 1);
+ int effMinWidth = (context.isStrict() || isFixedWidth(context) ? minWidth : 1);
int minEndPos = position + effMinWidth;
if (minEndPos > length) {
return ~position;
}
- int effMaxWidth = (context.isStrict() || isFixedWidth() ? maxWidth : 9) + Math.max(subsequentWidth, 0);
+ int effMaxWidth = (context.isStrict() || isFixedWidth(context) ? maxWidth : 9) + Math.max(subsequentWidth, 0);
long total = 0;
BigInteger totalBig = null;
int pos = position;
@@ -2866,6 +2874,21 @@
this.subsequentWidth + subsequentWidth);
}
+ /**
+ * For a ReducedPrinterParser, fixed width is false if the mode is strict,
+ * otherwise it is set as for NumberPrinterParser.
+ * @param context the context
+ * @return if the field is fixed width
+ * @see DateTimeFormatterBuilder#appendValueReduced(java.time.temporal.TemporalField, int, int, int)
+ */
+ @Override
+ boolean isFixedWidth(DateTimeParseContext context) {
+ if (context.isStrict() == false) {
+ return false;
+ }
+ return super.isFixedWidth(context);
+ }
+
@Override
public String toString() {
return "ReducedValue(" + field + "," + minWidth + "," + maxWidth + "," + (baseDate != null ? baseDate : baseValue) + ")";