Permalink
Browse files

Fix for a bug where dates with formats starting with leading '+' sign…

… before the year part were getting parsed improperly
  • Loading branch information...
1 parent 2d9d9cd commit 4d7255901c897a8573e1a75c9e6927103de20ba2 Hari Shankar committed Nov 13, 2013
Showing with 10 additions and 9 deletions.
  1. +10 −9 src/main/java/org/joda/time/format/DateTimeFormatterBuilder.java
View
19 src/main/java/org/joda/time/format/DateTimeFormatterBuilder.java
@@ -1330,25 +1330,22 @@ public int parseInto(DateTimeParserBucket bucket, String text, int position) {
int limit = Math.min(iMaxParsedDigits, text.length() - position);
boolean negative = false;
+ boolean hasPlusSign = false;
int length = 0;
while (length < limit) {
char c = text.charAt(position + length);
if (length == 0 && (c == '-' || c == '+') && iSigned) {
negative = c == '-';
+ hasPlusSign = c == '+';
// Next character must be a digit.
if (length + 1 >= limit ||
(c = text.charAt(position + length + 1)) < '0' || c > '9')
{
break;
}
-
- if (negative) {
- length++;
- } else {
- // Skip the '+' for parseInt to succeed.
- position++;
- }
+
+ length++;
// Expand the limit to disregard the sign character.
limit = Math.min(limit + 1, text.length() - position);
continue;
@@ -1367,10 +1364,14 @@ public int parseInto(DateTimeParserBucket bucket, String text, int position) {
if (length >= 9) {
// Since value may exceed integer limits, use stock parser
// which checks for this.
- value = Integer.parseInt(text.substring(position, position += length));
+ if(hasPlusSign) {
+ value = Integer.parseInt(text.substring(position + 1, position += length));
+ } else {
+ value = Integer.parseInt(text.substring(position, position += length));
+ }
} else {
int i = position;
- if (negative) {
+ if (negative || hasPlusSign) {
i++;
}
try {

0 comments on commit 4d72559

Please sign in to comment.