A LocalDateRange represents a range of dates, from a start date to an end date.
Instances can be constructed from either a half-open or a closed range of dates.
Internally, the class stores the start and end dates, with the start inclusive and the end exclusive.
The end date is always greater than or equal to the start date.
The constants LocalDate.MIN and LocalDate.MAX can be used
to indicate an unbounded far-past or far-future. Note that there is no difference
between a half-open and a closed range when the end is LocalDate.MAX.
Empty ranges are allowed.
No range can end at LocalDate.MIN or LocalDate.MIN.plusDays(1).
No range can start at LocalDate.MAX or LocalDate.MAX.minusDays(1).
No empty range can exist at LocalDate.MIN or LocalDate.MAX.
Date ranges are not comparable. To compare the length of two ranges, it is generally recommended to compare the number of days they contain.
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 LocalDateRange | ALL
A range over the whole time-line. |
| private final LocalDate | end
The end date (exclusive). |
| private static final LocalDate | MAXM1
The day before the MAX date. |
| private static final LocalDate | MINP1
The day after the MIN date. |
| private static final long | serialVersionUID
Serialization version. |
| private final LocalDate | start
The start date (inclusive). |
| Access | Constructor and Description |
|---|---|
| private | LocalDateRange(LocalDate
the start date, inclusive, validated not null startInclusive, LocalDate the end date, exclusive, validated not null endExclusive)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if this range abuts the other rangethe other range, not null other)Checks if this range abuts the specified range. |
| public boolean | |
| public boolean | Returns: true if this range contains all dates in the other rangethe other range to check for, not null other)Checks if this range encloses the specified range. |
| public boolean | Returns: true if this is equal to the other rangethe object to check, null returns false obj)Overrides java. Checks if this range is equal to another range. |
| public LocalDate | |
| public LocalDate | |
| public LocalDate | |
| public int | Returns: a suitable hash codeOverrides java. A hash code for this range. |
| public LocalDateRange | Returns: the range that is the intersection of the two rangesthe other range to check for, not null other)Calculates the range that is the intersection of this range and the specified range. |
| public boolean | |
| public boolean | Returns: true if every date in this range is after every date in the other rangethe other range to compare to, not null other)Checks if this range is after the specified range. |
| public boolean | |
| public boolean | Returns: true if every date in this range is before every date in the other rangethe other range to compare to, not null range)Checks if this range is before the specified range. |
| public boolean | Returns: true if this range is connected to the other rangethe other range, not null other)Checks if this range is connected to the specified range. |
| public boolean | |
| public boolean | |
| public boolean | |
| public int | Returns: the length in days, Integer.MAX_VALUE if unbounded or too largeObtains the length of this range in days. |
| public static LocalDateRange | |
| public static LocalDateRange | |
| public static LocalDateRange | |
| public static LocalDateRange | |
| public static LocalDateRange | Returns: the range, with an unbounded start and unbounded endObtains a range that is unbounded at the start and end. |
| public static LocalDateRange | Returns: the range, with an unbounded endthe inclusive start date, startInclusive)LocalDate.MIN treated as unbounded, not nullObtains a range from and including the specified start date. |
| public static LocalDateRange | Returns: the range, with an unbounded startthe exclusive end date, endExclusive)LocalDate.MAX treated as unbounded, not nullObtains a range up to, but not including, the specified end date. |
| public boolean | Returns: true if the time ranges overlapthe time range to compare to, null means a zero length range now other)Checks if this range overlaps the specified range. |
| public static LocalDateRange | Returns: the parsed range, not nullthe text to parse, not null text)Obtains an instance of |
| public LocalDateRange | Returns: the range that spans the two rangesthe other range to check for, not null other)Calculates the smallest range that encloses this range and the specified range. |
| public Stream | Returns: the stream of dates from the start to the endStreams the set of dates included in the range. |
| public Period | |
| public String | Returns: a string representation of this date, not nullOverrides java. Outputs this range as a |
| public LocalDateRange | Returns: the range that is the union of the two rangesthe other range to check for, not null other)Calculates the range that is the union of this range and the specified range. |
| public LocalDateRange | Returns: a copy of this range with the end date adjustedthe adjuster to use, not null adjuster)Returns a copy of this range with the end date adjusted. |
| public LocalDateRange | Returns: a copy of this range with the start date adjustedthe adjuster to use, not null adjuster)Returns a copy of this range with the start date adjusted. |
| ALL | back to summary |
|---|---|
| public static final LocalDateRange ALL A range over the whole time-line. | |
| end | back to summary |
|---|---|
| private final LocalDate end The end date (exclusive). | |
| MAXM1 | back to summary |
|---|---|
| private static final LocalDate MAXM1 The day before the MAX date. | |
| MINP1 | back to summary |
|---|---|
| private static final LocalDate MINP1 The day after the MIN date. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| start | back to summary |
|---|---|
| private final LocalDate start The start date (inclusive). | |
| LocalDateRange | back to summary |
|---|---|
| private LocalDateRange(LocalDate startInclusive, LocalDate endExclusive) Constructor. | |
| abuts | back to summary |
|---|---|
| public boolean abuts(LocalDateRange other) Checks if this range abuts the specified range. The result is true if the end of this range is the start of the other, or vice versa. An empty range does not abut itself.
| |
| contains | back to summary |
|---|---|
| public boolean contains(LocalDate date) Checks if this range contains the specified date.
This checks if the specified date is within the bounds of this range.
If this range is empty then this method always returns false.
Else if this range has an unbounded start then
| |
| encloses | back to summary |
|---|---|
| public boolean encloses(LocalDateRange other) Checks if this range encloses the specified range. This checks if the bounds of the specified range are within the bounds of this range. An empty range encloses itself.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Checks if this range is equal to another range.
Compares this | |
| getEnd | back to summary |
|---|---|
| public LocalDate getEnd() Gets the end date of this range, exclusive.
This will return
This never returns
| |
| getEndInclusive | back to summary |
|---|---|
| public LocalDate getEndInclusive() Gets the end date of this range, inclusive.
This will return This returns the date before the end date.
This never returns
| |
| getStart | back to summary |
|---|---|
| public LocalDate getStart() Gets the start date of this range, inclusive.
This will return
This never returns
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. A hash code for this range.
| |
| intersection | back to summary |
|---|---|
| public LocalDateRange intersection(LocalDateRange other) Calculates the range that is the intersection of this range and the specified range. This finds the intersection of two ranges. This throws an exception if the two ranges are not connected.
| |
| isAfter | back to summary |
|---|---|
| public boolean isAfter(LocalDate date) Checks if this range is after the specified date. The result is true if every date in this range is after the specified date. An empty range behaves as though it is a date for comparison purposes.
| |
| isAfter | back to summary |
|---|---|
| public boolean isAfter(LocalDateRange other) Checks if this range is after the specified range. The result is true if every date in this range is after every date in the specified range. An empty range behaves as though it is a date for comparison purposes.
| |
| isBefore | back to summary |
|---|---|
| public boolean isBefore(LocalDate date) Checks if this range is before the specified date. The result is true if every date in this range is before the specified date. An empty range behaves as though it is a date for comparison purposes.
| |
| isBefore | back to summary |
|---|---|
| public boolean isBefore(LocalDateRange range) Checks if this range is before the specified range. The result is true if every date in this range is before every date in the specified range. An empty range behaves as though it is a date for comparison purposes.
| |
| isConnected | back to summary |
|---|---|
| public boolean isConnected(LocalDateRange other) Checks if this range is connected to the specified range. The result is true if the two ranges have an enclosed range in common, even if that range is empty. An empty range 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 end date. An empty range is never unbounded.
| |
| isUnboundedEnd | back to summary |
|---|---|
| public boolean isUnboundedEnd() Checks if the end of the range is unbounded. An unbounded range is never empty.
| |
| isUnboundedStart | back to summary |
|---|---|
| public boolean isUnboundedStart() Checks if the start of the range is unbounded. An unbounded range is never empty.
| |
| lengthInDays | back to summary |
|---|---|
| public int lengthInDays() Obtains the length of this range in days.
This returns the number of days between the start and end dates.
If the range is too large, the length will be
| |
| of | back to summary |
|---|---|
| public static LocalDateRange of(LocalDate startInclusive, LocalDate endExclusive) Obtains a half-open range of dates, including the start and excluding the end.
The range includes the start date and excludes the end date, unless the end is
The constants
The start inclusive date must not be
| |
| of | back to summary |
|---|---|
| public static LocalDateRange of(LocalDate startInclusive, Period period) Obtains an instance of The end date is calculated as the start plus the duration. The period must not be negative.
The constant
The period must not be zero or one day when the start date is
| |
| ofClosed | back to summary |
|---|---|
| public static LocalDateRange ofClosed(LocalDate startInclusive, LocalDate endInclusive) Obtains a closed range of dates, including the start and end. The range includes the start date and the end date. The end date must be equal to or after the start date.
The constants
The start inclusive date must not be
| |
| ofEmpty | back to summary |
|---|---|
| public static LocalDateRange ofEmpty(LocalDate date) Obtains an empty date range located at the specified date.
The empty range has zero length and contains no other dates or ranges.
An empty range cannot be located at
| |
| ofUnbounded | back to summary |
|---|---|
| public static LocalDateRange ofUnbounded() Obtains a range that is unbounded at the start and end.
| |
| ofUnboundedEnd | back to summary |
|---|---|
| public static LocalDateRange ofUnboundedEnd(LocalDate startInclusive) Obtains a range from and including the specified start date.
The range includes all dates from the start date to the unbounded end, denoted by
| |
| ofUnboundedStart | back to summary |
|---|---|
| public static LocalDateRange ofUnboundedStart(LocalDate endExclusive) Obtains a range up to, but not including, the specified end date.
The range includes all dates from the unbounded start, denoted by
| |
| overlaps | back to summary |
|---|---|
| public boolean overlaps(LocalDateRange other) Checks if this range overlaps the specified range. The result is true if the two ranges share some part of the time-line. An empty range overlaps itself.
This is equivalent to
| |
| parse | back to summary |
|---|---|
| public static LocalDateRange parse(CharSequence text) Obtains an instance of The string must consist of one of the following three formats:
| |
| span | back to summary |
|---|---|
| public LocalDateRange span(LocalDateRange other) Calculates the smallest range that encloses this range and the specified range. The result of this method will enclose this range and the specified range.
| |
| stream | back to summary |
|---|---|
| public Stream Streams the set of dates included in the range. This returns a stream consisting of each date in the range. The stream is ordered. | |
| toPeriod | back to summary |
|---|---|
| public Period toPeriod() Obtains the length of this range as a period.
This returns the
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Outputs this range as a
The output will be the ISO-8601 format formed by combining the
| |
| union | back to summary |
|---|---|
| public LocalDateRange union(LocalDateRange other) Calculates the range that is the union of this range and the specified range. This finds the union of two ranges. This throws an exception if the two ranges are not connected.
| |
| withEnd | back to summary |
|---|---|
| public LocalDateRange withEnd(TemporalAdjuster adjuster) Returns a copy of this range with the end date adjusted.
This returns a new instance with the exclusive end date altered.
Since For example, to adjust the end to one week later: range = range.withEnd(date -> date.plus(1, ChronoUnit.WEEKS));
| |
| withStart | back to summary |
|---|---|
| public LocalDateRange withStart(TemporalAdjuster adjuster) Returns a copy of this range with the start date adjusted.
This returns a new instance with the start date altered.
Since For example, to adjust the start to one week earlier: range = range.withStart(date -> date.minus(1, ChronoUnit.WEEKS));
| |