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

feedback on JSR310 #353

Closed hohwille closed 8 years ago

hohwille commented 9 years ago

JSR310 is really a great improvement compared to what we had before with Date and Calendar. However, the API of JSR310 has many pitfalls and is partially academic. I am leaving this feedback here in the hope that someone might care even though I assume that this will be closed without anybody caring and after Java8 is out my feedback is maybe too late anyways...

I make a simple example to make a story of it: all I want to do is having two exact points in time (both in UTC). Further I want to calculate the number of days between those points ignoring the time.

So I do not want to say that you did bad work. If the API is used properly everything is fine. However, you created an expert API that has several pitfalls and is far from being used intuitively. Maybe such intuitive API would be impossible to create. However, a design that allows such clear types but runtime errors for things obvious at compile-time is really a big pitfall for every newbie.

jodastephen commented 8 years ago

These two APIs can calculate the difference between two Instant objects:

Duration.between(a, b).toDays()
ChronoUnit.DAYS.between(a, b)

The LocalDate.from(instant) issue is well known. The problem is that LocalDate needs a time-zone to extract data from an Instant and no time-zone is specified (it would be incorrect to choose either UTC or the system time-zone). The situation will be improved if this JDK issue is fixed.

The Duration.get(ChronoUnit.DAYS) issue is answered here. The method name "get" is simply wrong for what it is, which is a low-level method.

Thanks for the feedback.

hohwille commented 8 years ago

Thanks for clarification. The more people get used to java.time the better documentation on the web will get. Thanks for your time, mate.