public class DateRangeBound extends Object
It is composed of a ZonedDateTime
field and a corresponding DateRangePrecision
.
Date range bounds are inclusive. The special value UNBOUNDED
denotes an un unbounded
(infinite) bound, represented by a *
sign.
This class is immutable and thread-safe.
Modifier and Type | Field and Description |
---|---|
static DateRangeBound |
UNBOUNDED
The unbounded
DateRangeBound instance. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
DateRangePrecision |
getPrecision()
Returns the precision of this bound.
|
ZonedDateTime |
getTimestamp()
Returns the timestamp of this bound.
|
int |
hashCode() |
boolean |
isUnbounded()
Whether this bound is unbounded (i.e.
|
static DateRangeBound |
lowerBound(ZonedDateTime timestamp,
DateRangePrecision precision)
Creates a date range lower bound from the given date and precision.
|
static DateRangeBound |
parseLowerBound(String source)
Parses the given input as a lower date range bound.
|
static DateRangeBound |
parseUpperBound(String source)
Parses the given input as an upper date range bound.
|
String |
toString()
Returns this bound as a Lucene-compliant string.
|
static DateRangeBound |
upperBound(ZonedDateTime timestamp,
DateRangePrecision precision)
Creates a date range upper bound from the given date and precision.
|
public static final DateRangeBound UNBOUNDED
DateRangeBound
instance. It is syntactically represented by a *
(star) sign.@NonNull public static DateRangeBound parseLowerBound(@NonNull String source) throws ParseException
The input should be a Lucene-compliant string.
The returned bound will have its precision inferred from the input, and its timestamp will be rounded down to that precision.
Note that, in order to align with the server's parsing behavior, dates will always be parsed in the UTC time zone.
NullPointerException
- if lowerBound
is null
.ParseException
- if the given input cannot be parsed.public static DateRangeBound parseUpperBound(String source) throws ParseException
The input should be a Lucene-compliant string.
The returned bound will have its precision inferred from the input, and its timestamp will be DateRangePrecision.roundUp(ZonedDateTime) rounded up} to that precision.
Note that, in order to align with the server's behavior (e.g. when using date range literals
in CQL query strings), dates must always be in the UTC time zone: an optional trailing Z
" is allowed, but no other time zone ID (not even UTC
, GMT
or +00:00
)
is permitted.
NullPointerException
- if upperBound
is null
.ParseException
- if the given input cannot be parsed.public static DateRangeBound lowerBound(ZonedDateTime timestamp, DateRangePrecision precision)
public static DateRangeBound upperBound(ZonedDateTime timestamp, DateRangePrecision precision)
public boolean isUnbounded()
*
value).@NonNull public ZonedDateTime getTimestamp()
IllegalStateException
- if this bound is unbounded.@NonNull public DateRangePrecision getPrecision()
IllegalStateException
- if this bound is unbounded.@NonNull public String toString()
Unbounded bounds always return "*
"; all other bounds are formatted in one of the
common ISO-8601 datetime formats, depending on their precision.
Note that Lucene expects timestamps in UTC only. Timezone presence is always optional, and if present, it must be expressed with the symbol "Z" exclusively. Therefore this method does not include any timezone information in the returned string, except for bounds with millisecond precision, where the symbol "Z" is always appended to the resulting string.
Copyright © 2017–2024. All rights reserved.