FULL PRODUCT VERSION :
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
With the new java.time API, a DateTimeFormatter containing "DD" fails on a 3-digit day-of-year value.
So for example, "123 2010" and "003 1980" fail to be parsed with: DateTimeFormatter.ofPattern("DD yyyy")
On the other hand, "123 2010" and "003 1980" are parsed correctly with both:
DateTimeFormatter.ofPattern("D yyyy")
and
DateTimeFormatter.ofPattern("DDD yyyy")
The javadoc says: "Up to three letters of 'D' can be specified."
So this implies that it is legal to specify two letters of 'D' & the above is effectively a bug.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the attached test case & observe the difference in exepcted and actual result.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
output is:
true
true
true
ACTUAL -
output is:
false
false
false
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
public class BugTest {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("DD yyyy");
public static void main(String[] args) {
System.out.println(isParsable("003 1980"));
System.out.println(isParsable("023 1980"));
System.out.println(isParsable("123 1980"));
}
private static boolean isParsable(String input) {
try {
LocalDate.parse(input, FORMATTER);
return true;
} catch (DateTimeParseException e) {
return false;
}
}
}
---------- END SOURCE ----------
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
With the new java.time API, a DateTimeFormatter containing "DD" fails on a 3-digit day-of-year value.
So for example, "123 2010" and "003 1980" fail to be parsed with: DateTimeFormatter.ofPattern("DD yyyy")
On the other hand, "123 2010" and "003 1980" are parsed correctly with both:
DateTimeFormatter.ofPattern("D yyyy")
and
DateTimeFormatter.ofPattern("DDD yyyy")
The javadoc says: "Up to three letters of 'D' can be specified."
So this implies that it is legal to specify two letters of 'D' & the above is effectively a bug.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the attached test case & observe the difference in exepcted and actual result.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
output is:
true
true
true
ACTUAL -
output is:
false
false
false
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
public class BugTest {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("DD yyyy");
public static void main(String[] args) {
System.out.println(isParsable("003 1980"));
System.out.println(isParsable("023 1980"));
System.out.println(isParsable("123 1980"));
}
private static boolean isParsable(String input) {
try {
LocalDate.parse(input, FORMATTER);
return true;
} catch (DateTimeParseException e) {
return false;
}
}
}
---------- END SOURCE ----------
- relates to
-
JDK-8148949 DateTimeFormatter pattern letters 'A','n','N'
-
- Resolved
-