Java – DateTime within interval in JodaTime


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.

Best Solution

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.)

Related Question