java.lang.Object | |||
↳ | org.joda.time.base.AbstractInterval | ||
↳ | org.joda.time.base.BaseInterval | ||
↳ | org.joda.time.Interval |
Interval is the standard implementation of an immutable time interval.
A time interval represents a period of time between two instants. Intervals are inclusive of the start instant and exclusive of the end. The end instant is always greater than or equal to the start instant.
Intervals have a fixed millisecond duration.
This is the difference between the start and end instants.
The duration is represented separately by ReadableDuration
.
As a result, intervals are not comparable.
To compare the length of two intervals, you should compare their durations.
An interval can also be converted to a ReadablePeriod
.
This represents the difference between the start and end points in terms of fields
such as years and days.
Interval is thread-safe and immutable.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs an interval from a start and end instant with the ISO
default chronology in the default time zone.
| |||||||||||
Constructs an interval from a start and end instant with the ISO
default chronology in the specified time zone.
| |||||||||||
Constructs an interval from a start and end instant with the
specified chronology.
| |||||||||||
Constructs an interval from a start and end instant.
| |||||||||||
Constructs an interval from a start instant and a duration.
| |||||||||||
Constructs an interval from a millisecond duration and an end instant.
| |||||||||||
Constructs an interval from a start instant and a time period.
| |||||||||||
Constructs an interval from a time period and an end instant.
| |||||||||||
Constructs a time interval by converting or copying from another object.
| |||||||||||
Constructs a time interval by converting or copying from another object,
overriding the chronology.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Does this interval abut with the interval specified.
| |||||||||||
Gets the gap between this interval and another interval.
| |||||||||||
Gets the overlap between this interval and another interval.
| |||||||||||
Get this interval as an immutable
Interval object
by returning this . | |||||||||||
Creates a new interval with the same start and end, but a different chronology.
| |||||||||||
Creates a new interval with the specified duration after the start instant.
| |||||||||||
Creates a new interval with the specified duration before the end instant.
| |||||||||||
Creates a new interval with the specified end instant.
| |||||||||||
Creates a new interval with the specified start millisecond instant.
| |||||||||||
Creates a new interval with the specified period after the start instant.
| |||||||||||
Creates a new interval with the specified period before the end instant.
| |||||||||||
Creates a new interval with the specified start instant.
| |||||||||||
Creates a new interval with the specified start millisecond instant.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.joda.time.base.BaseInterval
| |||||||||||
From class
org.joda.time.base.AbstractInterval
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.joda.time.ReadableInterval
|
Constructs an interval from a start and end instant with the ISO default chronology in the default time zone.
startInstant | start of this interval, as milliseconds from 1970-01-01T00:00:00Z. |
---|---|
endInstant | end of this interval, as milliseconds from 1970-01-01T00:00:00Z. |
IllegalArgumentException | if the end is before the start |
---|
Constructs an interval from a start and end instant with the ISO default chronology in the specified time zone.
startInstant | start of this interval, as milliseconds from 1970-01-01T00:00:00Z. |
---|---|
endInstant | end of this interval, as milliseconds from 1970-01-01T00:00:00Z. |
zone | the time zone to use, null means default zone |
IllegalArgumentException | if the end is before the start |
---|
Constructs an interval from a start and end instant with the specified chronology.
startInstant | start of this interval, as milliseconds from 1970-01-01T00:00:00Z. |
---|---|
endInstant | end of this interval, as milliseconds from 1970-01-01T00:00:00Z. |
chronology | the chronology to use, null is ISO default |
IllegalArgumentException | if the end is before the start |
---|
Constructs an interval from a start and end instant.
The chronology used is that of the start instant.
start | start of this interval, null means now |
---|---|
end | end of this interval, null means now |
IllegalArgumentException | if the end is before the start |
---|
Constructs an interval from a start instant and a duration.
start | start of this interval, null means now |
---|---|
duration | the duration of this interval, null means zero length |
IllegalArgumentException | if the end is before the start |
---|---|
ArithmeticException | if the end instant exceeds the capacity of a long |
Constructs an interval from a millisecond duration and an end instant.
duration | the duration of this interval, null means zero length |
---|---|
end | end of this interval, null means now |
IllegalArgumentException | if the end is before the start |
---|---|
ArithmeticException | if the start instant exceeds the capacity of a long |
Constructs an interval from a start instant and a time period.
When forming the interval, the chronology from the instant is used if present, otherwise the chronology of the period is used.
start | start of this interval, null means now |
---|---|
period | the period of this interval, null means zero length |
IllegalArgumentException | if the end is before the start |
---|---|
ArithmeticException | if the end instant exceeds the capacity of a long |
Constructs an interval from a time period and an end instant.
When forming the interval, the chronology from the instant is used if present, otherwise the chronology of the period is used.
period | the period of this interval, null means zero length |
---|---|
end | end of this interval, null means now |
IllegalArgumentException | if the end is before the start |
---|---|
ArithmeticException | if the start instant exceeds the capacity of a long |
Constructs a time interval by converting or copying from another object.
The recognised object types are defined in
ConverterManager
and
include ReadableInterval and String.
The String formats are described by dateTimeParser()
and standard()
, and may be 'datetime/datetime',
'datetime/period' or 'period/datetime'.
interval | the time interval to copy |
---|
IllegalArgumentException | if the interval is invalid |
---|
Constructs a time interval by converting or copying from another object, overriding the chronology.
The recognised object types are defined in
ConverterManager
and
include ReadableInterval and String.
The String formats are described by dateTimeParser()
and standard()
, and may be 'datetime/datetime',
'datetime/period' or 'period/datetime'.
interval | the time interval to copy |
---|---|
chronology | the chronology to use, null means ISO default |
IllegalArgumentException | if the interval is invalid |
---|
Does this interval abut with the interval specified.
Intervals are inclusive of the start instant and exclusive of the end. An interval abuts if it starts immediately after, or ends immediately before this interval without overlap. A zero duration interval abuts with itself.
When two intervals are compared the result is one of three states: (a) they abut, (b) there is a gap between them, (c) they overlap. The abuts state takes precedence over the other two, thus a zero duration interval at the start of a larger interval abuts and does not overlap.
For example:
[09:00 to 10:00) abuts [08:00 to 08:30) = false (completely before) [09:00 to 10:00) abuts [08:00 to 09:00) = true [09:00 to 10:00) abuts [08:00 to 09:01) = false (overlaps) [09:00 to 10:00) abuts [09:00 to 09:00) = true [09:00 to 10:00) abuts [09:00 to 09:01) = false (overlaps) [09:00 to 10:00) abuts [10:00 to 10:00) = true [09:00 to 10:00) abuts [10:00 to 10:30) = true [09:00 to 10:00) abuts [10:30 to 11:00) = false (completely after) [14:00 to 14:00) abuts [14:00 to 14:00) = true [14:00 to 14:00) abuts [14:00 to 15:00) = true [14:00 to 14:00) abuts [13:00 to 14:00) = true
interval | the interval to examine, null means now |
---|
Gets the gap between this interval and another interval. The other interval can be either before or after this interval.
Intervals are inclusive of the start instant and exclusive of the end. An interval has a gap to another interval if there is a non-zero duration between them. This method returns the amount of the gap only if the intervals do actually have a gap between them. If the intervals overlap or abut, then null is returned.
When two intervals are compared the result is one of three states: (a) they abut, (b) there is a gap between them, (c) they overlap. The abuts state takes precedence over the other two, thus a zero duration interval at the start of a larger interval abuts and does not overlap.
The chronology of the returned interval is the same as that of this interval (the chronology of the interval parameter is not used). Note that the use of the chronology was only correctly implemented in version 1.3.
interval | the interval to examine, null means now |
---|
Gets the overlap between this interval and another interval.
Intervals are inclusive of the start instant and exclusive of the end. An interval overlaps another if it shares some common part of the datetime continuum. This method returns the amount of the overlap, only if the intervals actually do overlap. If the intervals do not overlap, then null is returned.
When two intervals are compared the result is one of three states: (a) they abut, (b) there is a gap between them, (c) they overlap. The abuts state takes precedence over the other two, thus a zero duration interval at the start of a larger interval abuts and does not overlap.
The chronology of the returned interval is the same as that of this interval (the chronology of the interval parameter is not used). Note that the use of the chronology was only correctly implemented in version 1.3.
interval | the interval to examine, null means now |
---|
Get this interval as an immutable Interval
object
by returning this
.
this
Creates a new interval with the same start and end, but a different chronology.
chronology | the chronology to use, null means ISO default |
---|
Creates a new interval with the specified duration after the start instant.
duration | the duration to add to the start to get the new end instant, null means zero |
---|
IllegalArgumentException | if the duration is negative |
---|
Creates a new interval with the specified duration before the end instant.
duration | the duration to add to the start to get the new end instant, null means zero |
---|
IllegalArgumentException | if the duration is negative |
---|
Creates a new interval with the specified end instant.
end | the end instant for the new interval, null means now |
---|
IllegalArgumentException | if the resulting interval has end before start |
---|
Creates a new interval with the specified start millisecond instant.
endInstant | the end instant for the new interval |
---|
IllegalArgumentException | if the resulting interval has end before start |
---|
Creates a new interval with the specified period after the start instant.
period | the period to add to the start to get the new end instant, null means zero |
---|
IllegalArgumentException | if the period is negative |
---|
Creates a new interval with the specified period before the end instant.
period | the period to add to the start to get the new end instant, null means zero |
---|
IllegalArgumentException | if the period is negative |
---|
Creates a new interval with the specified start instant.
start | the start instant for the new interval, null means now |
---|
IllegalArgumentException | if the resulting interval has end before start |
---|
Creates a new interval with the specified start millisecond instant.
startInstant | the start instant for the new interval |
---|
IllegalArgumentException | if the resulting interval has end before start |
---|