public interface TimespanI
getDateStart() = null: Unbounded in the past (-infinity).getDateEnd() = null: Unbounded in the future (+infinity).null: Interval is completely unbounded (isAlwaysValid()).[startDate, endDate].isValid(), isValidOn(Date), and
isPartiallyValidDuringDays(TimespanI).isValidAtMoment(Date) and
isPartiallyValidAtAnyMomentDuring(TimespanI).isValid(), isValidOn(Date), isValidAtMoment(Date)) or relative to it
(isValidAtOrBefore(Date), isValidAtOrAfter(Date)).overlapsWith(TimespanI, boolean), isPartiallyValidDuringDays(TimespanI)).isCompletelyValidDuring(TimespanI)).startsBeforeOrOnEndOf(TimespanI, boolean), endsAfterOrOnStartOf(TimespanI, boolean)).numberOfDays())
or shared with another (overlappingDaysWith(TimespanI)).checkConsistentDates())
and enforce closed boundaries (checkIsClosedTimespanWithConsistentDates()).| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
$0 |
static java.lang.String |
L10N_KEY_ERR_INCONSISTENT_DATES |
static java.lang.String |
L10N_KEY_ERR_INDET_NUMBER_OVERLAPPING |
static java.lang.String |
L10N_KEY_ERR_UNWANTED_OPEN_TIMESPAN |
| Modifier and Type | Method and Description |
|---|---|
default void |
checkConsistentDates()
Validates that this instance’s start date chronologically precedes or equals its end date.
|
static void |
checkConsistentDates(java.util.Date from,
java.util.Date till)
Validates that the start date chronologically precedes or equals the end date.
|
static void |
checkConsistentDates(java.util.Date from,
java.util.Date till,
boolean signalIllegalState)
Validates that the start date chronologically precedes or equals the end date,
throwing a configurable runtime exception if the interval is inverted.
|
default boolean |
checkIsClosedTimespanWithConsistentDates()
Checks whether this timespan is closed (both start and end dates are defined)
and has consistent date boundaries.
|
default boolean |
checkIsClosedTimespanWithConsistentDates(boolean doThrowIfOpen)
Checks whether this timespan is closed (both start and end dates are defined)
and has consistent date boundaries, with configurable enforcement for open intervals.
|
default boolean |
coversAtMostOneMonth()
Checks if this interval spans at most one calendar month.
|
default boolean |
endsAfterOrOnStartOf(TimespanI otherTS)
Checks if this interval’s end boundary is chronologically after the start boundary of
otherTS. |
default boolean |
endsAfterOrOnStartOf(TimespanI otherTS,
boolean sameDayCounts)
Checks if this interval’s end boundary is chronologically after or on the start boundary of
otherTS. |
default boolean |
equalDates(TimespanI otherTS)
Checks whether this interval defines identical start and end boundaries as
otherTS. |
static boolean |
equalDates(TimespanI oneTS,
TimespanI otherTS)
Null-safe comparison whether two intervals define identical start and end boundaries.
|
java.util.Date |
getDateEnd()
Returns the end boundary date of this interval.
|
java.util.Date |
getDateStart()
Returns the start boundary date of this interval.
|
default boolean |
hasUndefinedTimespan()
Checks if both boundary dates of this interval are undefined (
null). |
default boolean |
isAlwaysValid()
Checks if this interval is completely unbounded.
|
default boolean |
isCompletelyValidDuring(java.util.Date from,
java.util.Date upto)
Checks if this interval is completely enclosed within the date range
[from, upto]. |
default boolean |
isCompletelyValidDuring(TimespanI during)
Checks if this interval is completely enclosed within the specified interval.
|
default boolean |
isPartiallyValidAtAnyMomentDuring(java.util.Date from,
java.util.Date upto)
Checks if this interval is valid at any exact millisecond moment between
from and upto. |
default boolean |
isPartiallyValidAtAnyMomentDuring(TimespanI during)
Checks if this interval is valid at any exact millisecond moment during the passed interval.
|
default boolean |
isPartiallyValidDuring(java.util.Date from,
java.util.Date upto)
Deprecated.
|
default boolean |
isPartiallyValidDuring(java.util.Date from,
java.util.Date upto,
boolean ignoreTime)
Deprecated.
Prefer
isPartiallyValidDuringDays(Date, Date) for calendar-day comparison or
isPartiallyValidAtAnyMomentDuring(Date, Date) for millisecond precision. |
default boolean |
isPartiallyValidDuring(TimespanI during)
Deprecated.
Prefer
isPartiallyValidDuringDays(TimespanI) for calendar-day comparison |
default boolean |
isPartiallyValidDuring(TimespanI during,
boolean ignoreTime)
Deprecated.
Prefer
isPartiallyValidDuringDays(TimespanI) for calendar-day comparison or
isPartiallyValidAtAnyMomentDuring(TimespanI) for millisecond precision. |
default boolean |
isPartiallyValidDuringDays(java.util.Date from,
java.util.Date upto)
Checks if this interval overlaps with the date range defined by
[from, upto]
on any calendar day. |
default boolean |
isPartiallyValidDuringDays(TimespanI during)
Checks if this interval overlaps with the passed interval on any calendar day.
|
default boolean |
isValid()
Checks if this interval is valid today at calendar-day resolution.
|
default boolean |
isValidAt(java.util.Date d)
Deprecated.
Prefer
isValidOn(Date). |
default boolean |
isValidAt(java.util.Date d,
boolean ignoreTime)
Deprecated.
Prefer
isValidOn(Date) for day comparison or
isValidAtMoment(Date) for instant comparison. |
default boolean |
isValidAtMoment(java.util.Date d)
Checks if this interval is valid at the exact millisecond instant specified by
d. |
default boolean |
isValidAtOrAfter(java.util.Date d)
Checks if this interval is valid on or after the specified date.
|
default boolean |
isValidAtOrBefore(java.util.Date d)
Checks if this interval is valid on or before the specified date.
|
default boolean |
isValidFromStartOfTime()
Checks if this interval is valid at the start of time.
|
default boolean |
isValidOn(java.util.Date d)
Checks if this interval is valid on the given calendar day.
|
default boolean |
isValidUntilEndOfTime()
Checks if this interval has no end boundary.
|
default int |
numberOfDays()
Returns the number of days this TimespanI covers or -1 if no number of days can be determined because at least one end is open.
|
default int |
overlappingDaysWith(TimespanI otherTS)
Returns the number of days this TimespanI does overlap with the passed TimespanI.
|
static boolean |
overlaps(TimespanI oneTS,
TimespanI otherTS,
boolean sameDayOverlaps)
Canonical static check determining whether two timespans overlap, with configurable
handling for adjacent boundaries on the same calendar day.
|
default boolean |
overlapsWith(TimespanI other)
Checks if this timespan overlaps with the specified timespan.
|
default boolean |
overlapsWith(TimespanI other,
boolean sameDayOverlaps)
Checks if this timespan overlaps with the specified timespan, with configurable
handling for adjacent boundaries on the same calendar day.
|
default boolean |
startsBeforeOrOnEndOf(TimespanI otherTS)
Checks if this interval’s start boundary is chronologically before the end boundary of
otherTS. |
default boolean |
startsBeforeOrOnEndOf(TimespanI otherTS,
boolean sameDayCounts)
Checks if this interval’s start boundary is chronologically before or on the end boundary of
otherTS. |
static final java.lang.String $0
static final java.lang.String L10N_KEY_ERR_INCONSISTENT_DATES
static final java.lang.String L10N_KEY_ERR_INDET_NUMBER_OVERLAPPING
static final java.lang.String L10N_KEY_ERR_UNWANTED_OPEN_TIMESPAN
static void checkConsistentDates(java.util.Date from,
java.util.Date till)
If from is strictly after till, an IllegalArgumentException
is thrown. Unbounded boundaries (null) are considered consistent.
Calling this is equivalent to checkConsistentDates(from, till, false).
from - the starting boundary date, or null if unbounded in the pasttill - the ending boundary date, or null if unbounded in the futurejava.lang.IllegalArgumentException - if from is chronologically after tillstatic void checkConsistentDates(java.util.Date from,
java.util.Date till,
boolean signalIllegalState)
An interval is considered consistent if:
null (unbounded interval), orfrom is chronologically before or identical to till.The signalIllegalState parameter controls the exception type raised upon violation:
false when validating incoming method arguments (raises IllegalArgumentException).true when asserting the integrity of an existing instance state (raises IllegalStateException).from - the starting boundary date, or null if unbounded in the pasttill - the ending boundary date, or null if unbounded in the futuresignalIllegalState - true to throw an IllegalStateException;
false to throw an IllegalArgumentExceptionjava.lang.IllegalArgumentException - if from is after till and signalIllegalState is falsejava.lang.IllegalStateException - if from is after till and signalIllegalState is truejava.util.Date getDateStart()
null if valid from the start of timejava.util.Date getDateEnd()
Note: In day-level comparisons (such as isValid() and isValidOn(Date)),
this date is treated as an inclusive calendar day (valid through 23:59:59.999 of that day).
In millisecond-level comparisons (isValidAtMoment(Date)), it is evaluated as an exact instant.
null if open-endeddefault void checkConsistentDates()
An interval is considered consistent if either boundary is null
(unbounded interval) or getDateStart() is chronologically before or identical
to getDateEnd().
java.lang.IllegalStateException - if getDateStart() is chronologically after getDateEnd()default boolean checkIsClosedTimespanWithConsistentDates()
An interval is closed if both getDateStart() and getDateEnd()
are non-null. If either boundary is null, this method returns
false without raising an exception. Inconsistent dates (start after end)
will always raise an IllegalArgumentException.
Calling this is equivalent to checkIsClosedTimespanWithConsistentDates(false).
true if this timespan is closed and validly ordered;
false if it is open-ended at either boundaryjava.lang.IllegalArgumentException - if getDateStart() is chronologically after getDateEnd()default boolean checkIsClosedTimespanWithConsistentDates(boolean doThrowIfOpen)
An interval is considered closed and consistent if:
getDateStart() and getDateEnd() are non-null, andgetDateStart() chronologically precedes or equals getDateEnd().Inconsistent dates (start strictly after end) are an illegal state and will
always raise an IllegalArgumentException. The doThrowIfOpen parameter
dictates how open-ended boundaries (at least one null) are handled:
false: Open boundaries are accepted as a regular non-match and return false.true: A closed interval is strictly enforced, raising an IllegalArgumentException
if either boundary is missing.doThrowIfOpen - true to throw an IllegalArgumentException if the timespan
is open at either boundary; false to return false insteadtrue if this timespan is closed and consistent;
false if open-ended at either boundary and doThrowIfOpen is falsejava.lang.IllegalArgumentException - if getDateStart() is chronologically after getDateEnd(),
or if the timespan is open-ended and doThrowIfOpen is truedefault boolean coversAtMostOneMonth()
Open-ended intervals (where either boundary is null) cannot be evaluated
against a fixed duration and return false.
true if the closed interval spans at most one month; false if open-endedjava.lang.IllegalStateException - if getDateStart() is chronologically after getDateEnd()default boolean isValid()
Equivalent to calling isValidOn(Date()).
true if today falls within [getDateStart(), getDateEnd()] as whole calendar daysdefault boolean isValidOn(java.util.Date d)
This evaluates against whole calendar days, ignoring hour/minute/second components. Both start and end dates are treated as inclusive.
d - the calendar date to checktrue if d falls within [getDateStart(), getDateEnd()]default boolean isValidAtMoment(java.util.Date d)
d.d - the exact timestamp to checktrue if d is on or after getDateStart()
and on or before getDateEnd()@Deprecated default boolean isValidAt(java.util.Date d)
isValidOn(Date).d - the calendar date to checktrue if d falls within [getDateStart(), getDateEnd()]@Deprecated
default boolean isValidAt(java.util.Date d,
boolean ignoreTime)
isValidOn(Date) for day comparison or
isValidAtMoment(Date) for instant comparison.d - the date to checkignoreTime - true to evaluate by calendar day;
false to evaluate by exact millisecondtrue if valid according to selected resolutiondefault boolean isPartiallyValidDuringDays(TimespanI during)
Evaluates boundaries at inclusive calendar-day resolution (ignoring time components).
during - the interval to check against, or null for an unbounded intervaltrue if both intervals share at least one calendar daydefault boolean isPartiallyValidDuringDays(java.util.Date from,
java.util.Date upto)
[from, upto]
on any calendar day.
Both boundaries are evaluated as inclusive calendar days.
from - start date (inclusive), or null if unbounded in pastupto - end date (inclusive), or null if unbounded in futuretrue if both ranges share at least one calendar daydefault boolean isPartiallyValidAtAnyMomentDuring(TimespanI during)
during - the interval to check against, or null for an unbounded intervaltrue if both intervals share an exact moment in timedefault boolean isPartiallyValidAtAnyMomentDuring(java.util.Date from,
java.util.Date upto)
from and upto.from - start timestamp (inclusive), or null if unbounded in pastupto - end timestamp (inclusive), or null if unbounded in futuretrue if both intervals share an exact millisecond@Deprecated default boolean isPartiallyValidDuring(TimespanI during)
isPartiallyValidDuringDays(TimespanI) for calendar-day comparisonduring - the interval to check againsttrue if there is any calendar-day overlap@Deprecated default boolean isPartiallyValidDuring(TimespanI during, boolean ignoreTime)
isPartiallyValidDuringDays(TimespanI) for calendar-day comparison or
isPartiallyValidAtAnyMomentDuring(TimespanI) for millisecond precision.during - the interval to check againstignoreTime - true to evaluate by calendar day;
false to evaluate by exact millisecondtrue if there is an overlap according to selected resolution@Deprecated
default boolean isPartiallyValidDuring(java.util.Date from,
java.util.Date upto)
isPartiallyValidDuringDays(Date, Date).[from, upto] at calendar-day resolution.from - start date (inclusive), or nullupto - end date (inclusive), or nulltrue if both intervals overlap on any calendar day@Deprecated
default boolean isPartiallyValidDuring(java.util.Date from,
java.util.Date upto,
boolean ignoreTime)
isPartiallyValidDuringDays(Date, Date) for calendar-day comparison or
isPartiallyValidAtAnyMomentDuring(Date, Date) for millisecond precision.[from, upto] with explicit resolution control.from - start boundary, or nullupto - end boundary, or nullignoreTime - true to evaluate by calendar day;
false to evaluate by exact millisecondtrue if there is an overlap according to selected resolutiondefault boolean isCompletelyValidDuring(java.util.Date from,
java.util.Date upto)
[from, upto].
Both boundaries of the enclosing range are evaluated at calendar-day resolution.
from - the start boundary of the enclosing range (inclusive), or null if unbounded in pastupto - the end boundary of the enclosing range (inclusive), or null if unbounded in futuretrue if this interval is entirely contained within [from, upto]default boolean isCompletelyValidDuring(TimespanI during)
Evaluates whether both the start and end boundaries of this interval fall
within during at calendar-day resolution.
during - the enclosing interval to test againsttrue if this interval is entirely contained within during;
false if during is null or does not fully contain this intervaldefault boolean isAlwaysValid()
true if both start and end dates are nulldefault boolean isValidFromStartOfTime()
true if getDateStart() is nulldefault boolean isValidUntilEndOfTime()
true if getDateEnd() is nulldefault boolean isValidAtOrBefore(java.util.Date d)
Evaluates whether getDateStart() chronologically precedes or matches d.
If this interval is unbounded in the past (isValidFromStartOfTime()),
this method always returns true.
d - the reference timestamp to test againsttrue if this interval starts on or before ddefault boolean isValidAtOrAfter(java.util.Date d)
Evaluates whether getDateEnd() chronologically succeeds or matches d.
If this interval is open-ended into the future (isValidUntilEndOfTime()),
this method always returns true.
d - the reference timestamp to test againsttrue if this interval ends on or after ddefault boolean hasUndefinedTimespan()
null).
Semantic alias for isAlwaysValid().
true if both start and end dates are nulldefault boolean overlapsWith(TimespanI other)
Touching or adjacent timespans (where one ends on the same day the other begins)
are not considered overlapping. Calling this is equivalent to
overlapsWith(other, 0).
other - the timespan to check for overlaptrue if this timespan overlaps with other;
false otherwise or if other is nulldefault boolean overlapsWith(TimespanI other, boolean sameDayOverlaps)
Two timespans overlap when both intervals share a common period in time.
The sameDayOverlaps parameter controls boundary evaluation when one interval
ends on the exact day that the other interval begins:
true: Adjacent intervals (e.g. interval A ends on the same calendar
day interval B begins) are counted as overlapping.false: Adjacent intervals are treated as consecutive/disjoint
and do not count as overlapping.other - the timespan to check for overlap with this instance, may be nullsameDayOverlaps - true to count boundary touching on the same day as an overlap;
false to treat adjacent boundaries as non-overlappingtrue if this timespan overlaps with other;
false otherwise or if other is nullstatic boolean overlaps(TimespanI oneTS, TimespanI otherTS, boolean sameDayOverlaps)
This method provides a strictly symmetric relation:
overlaps(a, b, s) == overlaps(b, a, s).
The sameDayOverlaps parameter controls boundary evaluation when one interval
ends on the exact day that the other interval begins:
true: Adjacent intervals (e.g. interval A ends on the same calendar
day interval B begins) are counted as overlapping.false: Adjacent intervals are treated as consecutive/disjoint
and do not count as overlapping.oneTS - the first timespan, may be nullotherTS - the second timespan, may be nullsameDayOverlaps - true to count boundary touching on the same day as an overlap;
false to treat adjacent boundaries as non-overlappingtrue if oneTS overlaps with otherTS;
false if they are disjoint or if either parameter is nulldefault int overlappingDaysWith(TimespanI otherTS)
other - the timespan to count the overlapping days with this timespan forjava.lang.IllegalArgumentException - if the passed TimespanI and this instance are both unlimited and thus infinity would be the resultjava.lang.IllegalStateException - if this instance or the passed TimespanI are not temporally consistentdefault int numberOfDays()
java.lang.IllegalStateException - if this instance is not temporally consistentdefault boolean endsAfterOrOnStartOf(TimespanI otherTS)
otherTS.
Adjacent boundaries on the exact same calendar day are not counted as satisfying
the condition. Calling this is equivalent to endsAfterOrOnStartOf(otherTS, false).
otherTS - the interval to compare againsttrue if this interval ends after otherTS starts;
false otherwise or if otherTS is nulldefault boolean endsAfterOrOnStartOf(TimespanI otherTS, boolean sameDayCounts)
otherTS.
The sameDayCounts parameter controls whether boundary touching on the same day counts as a match:
true: The same calendar day counts as satisfying the condition (evaluates >= on day level).false: The same day does not count; this interval must end strictly after the start
of otherTS (evaluates strict > via after()).otherTS - the interval to compare againstsameDayCounts - true to count the same calendar day as a match;
false to require strict inequality (same day does not count)true if the condition is satisfied; false otherwise or if otherTS is nulldefault boolean startsBeforeOrOnEndOf(TimespanI otherTS)
otherTS.
Adjacent boundaries on the exact same calendar day are not counted as satisfying
the condition. Calling this is equivalent to startsBeforeOrOnEndOf(otherTS, false).
otherTS - the interval to compare againsttrue if this interval starts before otherTS ends;
false otherwise or if otherTS is nulldefault boolean startsBeforeOrOnEndOf(TimespanI otherTS, boolean sameDayCounts)
otherTS.
The sameDayCounts parameter controls whether boundary touching on the same day counts as a match:
true: The same calendar day counts as satisfying the condition (evaluates <= on day level).false: The same day does not count; this interval must start strictly before the end
of otherTS (evaluates strict < via before()).otherTS - the interval to compare againstsameDayCounts - true to count the same calendar day as a match;
false to require strict inequality (same day does not count)true if the condition is satisfied; false otherwise or if otherTS is nullstatic boolean equalDates(TimespanI oneTS, TimespanI otherTS)
oneTS - the first interval, may be nullotherTS - the second interval, may be nulltrue if both intervals are null or define identical boundary dates;
false otherwisedefault boolean equalDates(TimespanI otherTS)
otherTS.otherTS - the interval to compare withtrue if both start dates match and both end dates match;
false if dates differ or if otherTS is nullCopyright © 2000-2026 OAshi S.à r.l. All Rights Reserved.