diff options
Diffstat (limited to 'java/text/SimpleDateFormat.java')
-rw-r--r-- | java/text/SimpleDateFormat.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/java/text/SimpleDateFormat.java b/java/text/SimpleDateFormat.java index 1e1952569..f78fdcb89 100644 --- a/java/text/SimpleDateFormat.java +++ b/java/text/SimpleDateFormat.java @@ -1101,11 +1101,21 @@ public class SimpleDateFormat extends DateFormat if (is_numeric) { numberFormat.setMinimumIntegerDigits(fmt_count); - if (limit_digits) - numberFormat.setMaximumIntegerDigits(fmt_count); if (maybe2DigitYear) index = pos.getIndex(); - Number n = numberFormat.parse(dateStr, pos); + Number n = null; + if (limit_digits) + { + // numberFormat.setMaximumIntegerDigits(fmt_count) may + // not work as expected. So we explicitly use substring + // of dateStr. + int origPos = pos.getIndex(); + pos.setIndex(0); + n = numberFormat.parse(dateStr.substring(origPos, origPos + fmt_count), pos); + pos.setIndex(origPos + pos.getIndex()); + } + else + n = numberFormat.parse(dateStr, pos); if (pos == null || ! (n instanceof Long)) return null; value = n.intValue() + offset; |