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

Parsing dates in non-ISO misses requested chronology #268

Closed jodastephen closed 11 years ago

jodastephen commented 11 years ago

Code was added to allow dates to be parsed in non-ISO chronologies. However, this doesn't fully take into account the chronology of the formatter as intended in the design.

There are two chronologies in use

Parse string "Minguo 1234-06-30" using a "formatter.withChronology(ThaiBuddhistChronology)" will parse the date using Minguo, and then convert the date to Thai before returning it.

jodastephen commented 11 years ago

First patch https://gist.github.com/jodastephen/5049319

jodastephen commented 11 years ago

On further examination, making this change would be really hard/complex and only benefit very limited use cases. Since most users will specify a concrete type as part of the parse (using ::from method reference) the chronology is already being applied. The withChronology and withZone methods on DateTimeFormatter are therefore best left as defaults.

Javadoc clarification: http://hg.openjdk.java.net/threeten/threeten/jdk/rev/569031ace043

The use during formatting turned out to be incomplete and capable of improvement. In particular, some edge cases that would confuse users, such as expecting a YearMonth to be converted to another calendar system, will now throw exceptions: http://hg.openjdk.java.net/threeten/threeten/jdk/rev/999f123d8687