An interval represents the time on the time-line between two Instants.
The class stores the start and end instants, with the start inclusive and the end exclusive.
The end instant is always greater than or equal to the start instant.
The Duration of an interval can be obtained, but is a separate concept.
An interval is connected to the time-line, whereas a duration is not.
Intervals are not comparable. To compare the length of two intervals, it is generally recommended to compare their durations.
This class must be treated as a value type. Do not synchronize, rely on the identity hash code or use the distinction between equals() and ==.
| Modifier and Type | Field and Description |
|---|---|
| public static final Interval | ALL
An interval over the whole time-line. |
| private final Instant | end
The end instant (exclusive). |
| private static final long | serialVersionUID
Serialization version. |
| private final Instant | start
The start instant (inclusive). |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public boolean | |
| public boolean | |
| public static Interval | |
| public boolean | |
| public boolean | Returns: true if this interval ends at or after the instantthe instant, not null instant)Checks if this interval ends after the specified instant. |
| public boolean | Returns: true if this interval ends at or before the instantthe instant, not null instant)Checks if this interval ends at or before the specified instant. |
| public boolean | Returns: true if this interval ends before the instantthe instant, not null instant)Checks if this interval ends before the specified instant. |
| public boolean | Returns: true if this is equal to the other intervalthe object to check, null returns false obj)Overrides java. Checks if this interval is equal to another interval. |
| public Instant | Returns: the end of the time interval, exclusiveGets the end of this time interval, exclusive. |
| public Instant | |
| public int | Returns: a suitable hash codeOverrides java. A hash code for this interval. |
| public Interval | Returns: the interval that is the intersection of the two intervalsthe other interval to check for, not null other)Calculates the interval that is the intersection of this interval and the specified interval. |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if this interval is connected to the other intervalthe other interval, not null other)Checks if this interval is connected to the specified interval. |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if start is unboundedChecks if the start of the interval is unbounded. |
| public static Interval | Returns: the half-open interval, not nullthe start instant, inclusive, startInclusive, Instant Instant#MIN treated as unbounded, not nullthe end instant, exclusive, endExclusive)Instant#MAX treated as unbounded, not nullObtains an instance of |
| public static Interval | |
| public static Interval | |
| public boolean | |
| public static Interval | Returns: the parsed interval, not nullthe text to parse, not null text)Obtains an instance of |
| private static Interval | |
| private static Interval | |
| private static Interval | |
| public Interval | |
| public static Interval | Returns: a newInstant with the specified start instant.the start instant, inclusive, not null startInclusive)Obtains an instance of |
| public boolean | Returns: true if this interval starts after the instantthe instant, not null instant)Checks if this interval starts on or after the specified instant. |
| public boolean | Returns: true if this interval starts at or after the instantthe instant, not null instant)Checks if this interval starts at or after the specified instant. |
| public boolean | Returns: true if this interval starts at or before the instantthe instant, not null instant)Checks if this interval starts at or before the specified instant. |
| public boolean | Returns: true if this interval starts before the instantthe instant, not null instant)Checks if this interval starts on or before the specified instant. |
| public Duration | |
| public String | Returns: a string representation of this instant, not nullOverrides java. Outputs this interval as a |
| public Interval | |
| public Interval | |
| public Interval |
| ALL | back to summary |
|---|---|
| public static final Interval ALL An interval over the whole time-line. | |
| end | back to summary |
|---|---|
| private final Instant end The end instant (exclusive). | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| start | back to summary |
|---|---|
| private final Instant start The start instant (inclusive). | |
| Interval | back to summary |
|---|---|
| private Interval(Instant startInclusive, Instant endExclusive) Constructor. | |
| abuts | back to summary |
|---|---|
| public boolean abuts(Interval other) Checks if this interval abuts the specified interval. The result is true if the end of this interval is the start of the other, or vice versa. An empty interval does not abut itself.
| |
| contains | back to summary |
|---|---|
| public boolean contains(Instant instant) Checks if this interval contains the specified instant.
This checks if the specified instant is within the bounds of this interval.
If this interval has an unbounded start then
This is equivalent to
| |
| encloses | back to summary |
|---|---|
| public boolean encloses(Interval other) Checks if this interval encloses the specified interval. This checks if the bounds of the specified interval are within the bounds of this interval. An empty interval encloses itself.
| |
| endingAt | back to summary |
|---|---|
| public static Interval endingAt(Instant endExclusive) Obtains an instance of | |
| endsAfter | back to summary |
|---|---|
| public boolean endsAfter(Instant instant) Checks if this interval ends after the specified instant.
This method compares the end of the interval to the instant.
An interval with an unbounded end is considered to end after
| |
| endsAtOrAfter | back to summary |
|---|---|
| public boolean endsAtOrAfter(Instant instant) Checks if this interval ends after the specified instant.
This method compares the end of the interval to the instant.
An interval with an unbounded end is considered to end after
| |
| endsAtOrBefore | back to summary |
|---|---|
| public boolean endsAtOrBefore(Instant instant) Checks if this interval ends at or before the specified instant.
This method compares the end of the interval to the instant.
An interval with an unbounded end is considered to end after
| |
| endsBefore | back to summary |
|---|---|
| public boolean endsBefore(Instant instant) Checks if this interval ends before the specified instant.
This method compares the end of the interval to the instant.
An interval with an unbounded end is considered to end after
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Checks if this interval is equal to another interval.
Compares this | |
| getEnd | back to summary |
|---|---|
| public Instant getEnd() Gets the end of this time interval, exclusive.
This will return
| |
| getStart | back to summary |
|---|---|
| public Instant getStart() Gets the start of this time interval, inclusive.
This will return
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. A hash code for this interval.
| |
| intersection | back to summary |
|---|---|
| public Interval intersection(Interval other) Calculates the interval that is the intersection of this interval and the specified interval. This finds the intersection of two intervals. This throws an exception if the two intervals are not connected.
| |
| isAfter | back to summary |
|---|---|
| public boolean isAfter(Interval interval) Checks if this interval is after the specified interval. The result is true if this interval starts after the end of the specified interval. Since intervals do not include their end points, this will return true if the two intervals abut. An empty interval behaves as though it is an instant for comparison purposes.
| |
| isAfter | back to summary |
|---|---|
| public boolean isAfter(Instant instant) Checks if this interval is after the specified instant. The result is true if this interval starts after the specified instant. An empty interval behaves as though it is an instant for comparison purposes.
This is equivalent to
| |
| isBefore | back to summary |
|---|---|
| public boolean isBefore(Interval interval) Checks if this interval is before the specified interval. The result is true if this interval ends before the start of the specified interval. Since intervals do not include their end points, this will return true if the two intervals abut. An empty interval behaves as though it is an instant for comparison purposes.
| |
| isBefore | back to summary |
|---|---|
| public boolean isBefore(Instant instant) Checks if this interval is before the specified instant. The result is true if this interval ends before the specified instant. Since intervals do not include their end points, this will return true if the instant equals the end of the interval. An empty interval behaves as though it is an instant for comparison purposes.
This is equivalent to
| |
| isConnected | back to summary |
|---|---|
| public boolean isConnected(Interval other) Checks if this interval is connected to the specified interval. The result is true if the two intervals have an enclosed interval in common, even if that interval is empty. An empty interval is connected to itself.
This is equivalent to
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Checks if the range is empty. An empty range occurs when the start date equals the inclusive end date.
| |
| isUnboundedEnd | back to summary |
|---|---|
| public boolean isUnboundedEnd() Checks if the end of the interval is unbounded.
| |
| isUnboundedStart | back to summary |
|---|---|
| public boolean isUnboundedStart() Checks if the start of the interval is unbounded.
| |
| of | back to summary |
|---|---|
| public static Interval of(Instant startInclusive, Instant endExclusive) Obtains an instance of The end instant must not be before the start instant.
| |
| of | back to summary |
|---|---|
| public static Interval of(Instant startInclusive, Duration duration) Obtains an instance of The end instant is calculated as the start plus the duration. The duration must not be negative.
| |
| of | back to summary |
|---|---|
| public static Interval of(Duration duration, Instant endExclusive) Obtains an instance of The start instant is calculated as the end minus the duration. The duration must not be negative.
| |
| overlaps | back to summary |
|---|---|
| public boolean overlaps(Interval other) Checks if this interval overlaps the specified interval. The result is true if the two intervals share some part of the time-line. An empty interval overlaps itself.
This is equivalent to
| |
| parse | back to summary |
|---|---|
| public static Interval parse(CharSequence text) Obtains an instance of The string must consist of one of the following four formats:
ISO-8601 supports a very wide range of possible inputs, many of which are not supported here. For example, basic format, week-based dates, ordinal dates and date-style period formats are not supported.
| |
| parseEndDateTime | back to summary |
|---|---|
| private static Interval parseEndDateTime(Instant start, ZoneOffset offset, CharSequence endStr) | |
| parseSplit | back to summary |
|---|---|
| private static Interval parseSplit(CharSequence startStr, CharSequence endStr) | |
| parseStartExtended | back to summary |
|---|---|
| private static Interval parseStartExtended(CharSequence startStr, CharSequence endStr) | |
| span | back to summary |
|---|---|
| public Interval span(Interval other) Calculates the smallest interval that encloses this interval and the specified interval. The result of this method will enclose this interval and the specified interval. | |
| startingAt | back to summary |
|---|---|
| public static Interval startingAt(Instant startInclusive) Obtains an instance of | |
| startsAfter | back to summary |
|---|---|
| public boolean startsAfter(Instant instant) Checks if this interval starts on or after the specified instant.
This method compares the start of the interval to the instant.
An interval with an unbounded start is considered to start at
| |
| startsAtOrAfter | back to summary |
|---|---|
| public boolean startsAtOrAfter(Instant instant) Checks if this interval starts at or after the specified instant.
This method compares the start of the interval to the instant.
An interval with an unbounded start is considered to start at
| |
| startsAtOrBefore | back to summary |
|---|---|
| public boolean startsAtOrBefore(Instant instant) Checks if this interval starts at or before the specified instant.
This method compares the start of the interval to the instant.
An interval with an unbounded start is considered to start at
| |
| startsBefore | back to summary |
|---|---|
| public boolean startsBefore(Instant instant) Checks if this interval starts on or before the specified instant.
This method compares the start of the interval to the instant.
An interval with an unbounded start is considered to start at
| |
| toDuration | back to summary |
|---|---|
| public Duration toDuration() Obtains the duration of this interval.
An
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Outputs this interval as a
The output will be the ISO-8601 format formed by combining the
| |
| union | back to summary |
|---|---|
| public Interval union(Interval other) Calculates the interval that is the union of this interval and the specified interval. This finds the union of two intervals. This throws an exception if the two intervals are not connected.
| |
| withEnd | back to summary |
|---|---|
| public Interval withEnd(Instant end) Returns a copy of this range with the specified end instant.
| |
| withStart | back to summary |
|---|---|
| public Interval withStart(Instant start) Returns a copy of this range with the specified start instant.
| |