An interval in Joda-Time represents an interval of time from one millisecond instant to another instant. Both instants are fully specified instants in the datetime continuum, complete with time zone.
Intervals are implemented as half-open, which is to say that the start instant is inclusive but the end instant is exclusive. The end is always greater than or equal to the start. The interval is also restricted to just one chronology and time zone.
You cannot compare intervals for order (i.e., they do not implement Comparable). If you want to compare the length of intervals you must obtain the duration of each and compare those.
Using Intervals in Joda-Time
Within Joda-Time an interval is represented by the ReadableInterval interface. There are two implementations of the interface provided:
The code can be used in various ways:
// interval from start to end DateTime start = new DateTime(2004, 12, 25, 0, 0, 0, 0); DateTime end = new DateTime(2005, 1, 1, 0, 0, 0, 0); Interval interval = new Interval(start, end);
Interval interval = ... DateTime start = interval.getStart(); DateTime end = interval.getEnd(); Chronology chrono = interval.getChronology(); Duration duration = interval.toDuration(); Period period = interval.toPeriod();
Note that the interface ReadableInterval should not be used like the collections API. The interface only contains the core subset of the operations. Instead, you should usually refer directly to the implementation classes in your APIs.
Joda-Time defines a null interval as a zero length interval from now to now. Thus, when a method is defined as taking a ReadableInterval, passing null in will be the same as passing in a zero length interval at the current time.