ThreeTen / threeten

This project was the home of code used to develop a modern date and time library for JDK8. Development has moved to OpenJDK and a separate backport project, threetenbp.
http://threeten.github.io/
191 stars 37 forks source link

LocalDate.parse("10000-12-31", DateTimeFormatter.ISO_LOCAL_DATE) throws DateTimeParseException #347

Closed abhinavrau closed 10 years ago

abhinavrau commented 10 years ago

Following test case is failing using the 0.8.1 version of the backport

public class SimpleTest  extends TestCase 
{
    public void testLocalDateWith5DigitYear()
    {
        LocalDate date = LocalDate.parse("10000-12-31",  DateTimeFormatter.ISO_LOCAL_DATE);
        assertEquals(10000, date.getYear());
    }

}

I get the following exception: org.threeten.bp.format.DateTimeParseException: Text '10000-12-31' could not be parsed at index 0

The javadoc for DateTimeFormatter.ISO_LOCAL_DATE states that it supports "Four digits or more for the year".

Is this is a bug? Any workarounds I can use in the meantime?

Thanks

Abhinav Rau

RogerRiggs commented 10 years ago

As described in the spec of DateTimeFormatter.ISO_LOCAL_DATE (used by LocalDate.parse) if there are more than 4 digits the sign (+/-) is required.
The java.time API shows the same behavior in SE 8.

jodastephen commented 10 years ago

Spec says "Four digits or more for the year. Years in the range 0000 to 9999 will be pre-padded by zero to ensure four digits. Years outside that range will have a prefixed positive or negative symbol. "

Closing, as not a bug.