JodaOrg / joda-time

Joda-Time is the widely used replacement for the Java date and time classes prior to Java SE 8.
http://www.joda.org/joda-time/
Apache License 2.0
4.98k stars 986 forks source link

More arithmetic for Durations #69

Closed bjoernpollex closed 8 years ago

bjoernpollex commented 11 years ago

I would like to have support for the following operations on Duration:

If no one objects to such operations, I would be happy to fork and implement them.

jodastephen commented 11 years ago

I would support multipliedBy(long), dividedBy(long) and negated() as per JSR-310. I tend to avoid double in Joda-Time.

The floor and ceil operations could be interesting, however the question is always where to draw the line.

Perhaps start with a pull request for multipliedBy, dividedBy and negated?

bjoernpollex commented 11 years ago

Thanks for the quick response. Pull request #72 implements the methods you suggested.

I agree that double does not really make sense in these APIs. The ideal way would be to provide a RationalNumber class and then an overload Duration.multipliedBy(RationNumber multiplicand). Would you support such an approach? (Alternatively an overload Duration.multipliedBy(long numerator, long denominator) would suffice I think, but internally I'd implement that with a RationalNumber class as well, to handle reduction among other things).

I would really like to see the floor and ceil methods in, because I have repeatedly had a need for them.

jodastephen commented 11 years ago

I think fractional multiplication is simply multipliedBy followed by dividedBy.

I think I'd accept a dividedBy(long, RoundingMode) which would cover floor and ceil.

a7i7 commented 8 years ago

Is this issue still open? I would like to work on this

jodastephen commented 8 years ago

If you'd like to raise a PR for dividedBy(long, RoundingMode) I'd consider it.

a7i7 commented 8 years ago

@jodastephen Hi. Here is the PR 379 implementing the above method. Kindly have a look at it.