views:

354

answers:

1

Is there a API method in JodaTime to see whether a DateTime is within [start, end], i.e. the boundary is included?

Only thing I found was new Interval(start, end).contains(dateTime) but this seems to give false if dateTime equals end.

+4  A: 

The easiest approach would be to create a new interval which is the old one extended by a millisecond if you need to do this often:

Interval inclusiveInterval = interval.withEndMillis(interval.getEndMillis() + 1);

Alternatively just use

if (interval.contains(dateTime) || interval.getEnd().isEqual(dateTime))

(The isEqual method ignores chronology and time zone.)

Jon Skeet
Yeah, I ended up using the latter one before you answered. Thanks anyway, I didn't notice that isEquals behaves like that.
egaga