I have Duration object which I want to return full duration in days (rounded up), so for:
Unfortunately toDays() method is returning only full days. Is there any method for getting ceil value?
The way you can do a ceil with integer division is to add 1 less than the denominator:
(numerator + denominator - 1) / denominator
So, do the same here: add 1 nanosecond less than 1 day to your duration, and then use toDays().
duration.plusDays(1).minusNanos(1).toDays()
Looking in the docs, it suggests that toDays() might only consider to second precision. However, this little demo shows that it works to nanosecond precision (at least for non-negative durations).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With