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

Period/Duration plus/minus #281

Closed jodastephen closed 11 years ago

jodastephen commented 11 years ago

Currently we have these methods:

Period.plus(Period)
Period.minus(Period)
Duration.plus(Duration)
Duration.minus(Duration)

now that we have a queryable interface, they should probably be:

Period.plus(TemporalAmount)
Period.minus(TemporalAmount)
Duration.plus(TemporalAmount)
Duration.minus(TemporalAmount)
RogerRiggs commented 11 years ago

Changing the signatures of the Duration.plus/minus method would reduce the value of static type checking. Those methods would now need to check for estimated Periods and might fail at at runtime.
It would also blur the distinction between human time and machine time. Opening up Period.plus/minus would require a definition of the rounding or truncation required to combine values with different units years/months/days and days/nano. While it could be well defined in the spec; it makes the behavior depend on the actual values supplied and harder to understand and use.

jodastephen commented 11 years ago

The main argument in favour of this is consistency, as other similar methods are lenient in their input (with the effect of changing compile time to runtime checking). cf LocalDate.plus(TemporalAmount).

jodastephen commented 11 years ago

Closing as Won'tFix. Issue #285 means that it is easy enough to do the conversion for those cases when it is needed. I'm more worried about the lack of mapping of weeks to days and quarters to months than this.