I'm using javac 15.0.1, on a Java SE8 project.
I have irregular input for LocalDate:
String fateDate = "1970-02-29"
;
With parse() of LocalDate I get this Exception (rightly so):
LocalDate.parse(fateDate);
Exception in thread "main" java.time.format.DateTimeParseException: Text '1970-02-29' could not be parsed: Invalid date 'February 29' as '1970' is not a leap year
But using a DateTimeFormatter does some sort of correction:
final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("y-M-d");
TemporalAccessor ta = dtf.parse(fateDate);
System.out.println(ta);
yields to:
{},ISO resolved to 1970-02-28
This behavior is the same with all months and all values for day<32. So, for April you do not get an exception for 31, but a LocalDate with 30 as value for day. This doesn't look like a perfect incarnation of "fail early"...
Why is there different behavior
- in LocalDate.parse() vs. DateTimeFormatter.parse()?
- in DateTimeFormatter for invalid days_of_month >31 vs. !>31?