public final class TimestampInterval extends IsoInterval<PlainTimestamp,TimestampInterval> implements Serializable
Defines a timestamp interval on local timeline.
| Modifier and Type | Field and Description |
|---|---|
static TimestampInterval |
ALWAYS
Constant for a timestamp interval from infinite past to infinite future.
|
| Modifier and Type | Method and Description |
|---|---|
MomentInterval |
at(ZonalOffset offset)
Combines this local timestamp interval with given timezone offset
to a global UTC-interval.
|
MomentInterval |
atUTC()
Combines this local timestamp interval with the timezone offset
UTC+00:00 to a global UTC-interval.
|
static TimestampInterval |
between(LocalDateTime start,
LocalDateTime end)
Creates a finite half-open interval between given time points.
|
static TimestampInterval |
between(PlainTimestamp start,
PlainTimestamp end)
Creates a finite half-open interval between given time points.
|
static Comparator<ChronoInterval<PlainTimestamp>> |
comparator()
Defines a comparator which sorts intervals first
by start boundary and then by length.
|
String |
formatISO(IsoDateStyle dateStyle,
IsoDecimalStyle decimalStyle,
ClockUnit precision,
InfinityStyle infinityStyle)
Prints the canonical form of this interval in given ISO-8601 style.
|
String |
formatReduced(IsoDateStyle dateStyle,
IsoDecimalStyle decimalStyle,
ClockUnit precision,
InfinityStyle infinityStyle)
Prints the canonical form of this interval in given reduced ISO-8601 style.
|
static TimestampInterval |
from(ChronoInterval<PlainTimestamp> interval)
Converts an arbitrary timestamp interval to an interval of this type.
|
Duration<IsoUnit> |
getDuration(Timezone tz,
IsoUnit... units)
Yields the length of this interval in given units and applies
a timezone offset correction .
|
<U extends IsoUnit> |
getDuration(U... units)
Yields the length of this interval in given units.
|
LocalDateTime |
getEndAsLocalDateTime()
Yields the end time point.
|
PlainTimestamp |
getEndAsTimestamp()
Yields the end time point.
|
LocalDateTime |
getStartAsLocalDateTime()
Yields the start time point.
|
PlainTimestamp |
getStartAsTimestamp()
Yields the start time point.
|
MomentInterval |
inStdTimezone()
Combines this local timestamp interval with the system timezone
to a global UTC-interval.
|
MomentInterval |
inTimezone(TZID tzid)
Combines this local timestamp interval with given timezone
to a global UTC-interval.
|
TimestampInterval |
move(long amount,
IsoUnit unit)
Moves this interval along the time axis by given units.
|
static TimestampInterval |
parse(CharSequence text,
ChronoParser<PlainTimestamp> parser,
BracketPolicy policy)
Interpretes given text as interval.
|
static TimestampInterval |
parse(CharSequence text,
ChronoParser<PlainTimestamp> startFormat,
char separator,
ChronoParser<PlainTimestamp> endFormat,
BracketPolicy policy,
ParseLog status)
Interpretes given text as interval.
|
static TimestampInterval |
parse(String text,
ChronoParser<PlainTimestamp> parser)
Interpretes given text as interval using a localized interval pattern.
|
static TimestampInterval |
parse(String text,
ChronoParser<PlainTimestamp> parser,
String intervalPattern)
Interpretes given text as interval using given interval pattern.
|
static TimestampInterval |
parseISO(String text)
Interpretes given ISO-conforming text as interval.
|
PlainTimestamp |
random()
Obtains a random timestamp within this interval.
|
static TimestampInterval |
since(LocalDateTime start)
Creates an infinite half-open interval since given start
timestamp.
|
static TimestampInterval |
since(PlainTimestamp start)
Creates an infinite half-open interval since given start
timestamp.
|
Stream<PlainTimestamp> |
stream(Duration<?> duration)
Obtains a stream iterating over every timestamp which is the result of addition of given duration
to start until the end of this interval is reached.
|
static Stream<PlainTimestamp> |
stream(Duration<?> duration,
PlainTimestamp start,
PlainTimestamp end)
Obtains a stream iterating over every timestamp which is the result of addition of given duration
to start until the end is reached.
|
Stream<TimestampInterval> |
streamPartitioned(DayPartitionRule rule)
Creates a partitioning stream of timestamp intervals where every day of this interval is partitioned
according to given partitioning rule.
|
static TimestampInterval |
until(LocalDateTime end)
Creates an infinite open interval until given end timestamp.
|
static TimestampInterval |
until(PlainTimestamp end)
Creates an infinite open interval until given end timestamp.
|
abuts, collapse, contains, contains, enclosedBy, encloses, equals, equivalentTo, findIntersection, finishedBy, finishes, get, getEnd, getStart, hashCode, intersects, isAfter, isAfter, isBefore, isBefore, isEmpty, meets, metBy, overlappedBy, overlaps, precededBy, precedes, print, print, print, print, startedBy, starts, toCanonical, toString, withClosedEnd, withClosedStart, withEnd, withEnd, withOpenEnd, withOpenStart, withStart, withStart, withValueisFinitepublic static final TimestampInterval ALWAYS
public static Comparator<ChronoInterval<PlainTimestamp>> comparator()
Defines a comparator which sorts intervals first by start boundary and then by length.
IllegalArgumentException - if applied on intervals which have
boundaries with extreme valuespublic static TimestampInterval between(PlainTimestamp start, PlainTimestamp end)
Creates a finite half-open interval between given time points.
start - timestamp of lower boundary (inclusive)end - timestamp of upper boundary (exclusive)IllegalArgumentException - if start is after endpublic static TimestampInterval between(LocalDateTime start, LocalDateTime end)
Creates a finite half-open interval between given time points.
start - timestamp of lower boundary (inclusive)end - timestamp of upper boundary (exclusive)IllegalArgumentException - if start is after endbetween(PlainTimestamp, PlainTimestamp)public static TimestampInterval since(PlainTimestamp start)
Creates an infinite half-open interval since given start timestamp.
start - timestamp of lower boundary (inclusive)public static TimestampInterval since(LocalDateTime start)
Creates an infinite half-open interval since given start timestamp.
start - timestamp of lower boundary (inclusive)since(PlainTimestamp)public static TimestampInterval until(PlainTimestamp end)
Creates an infinite open interval until given end timestamp.
end - timestamp of upper boundary (exclusive)public static TimestampInterval until(LocalDateTime end)
Creates an infinite open interval until given end timestamp.
end - timestamp of upper boundary (exclusive)until(PlainTimestamp)public static TimestampInterval from(ChronoInterval<PlainTimestamp> interval)
Converts an arbitrary timestamp interval to an interval of this type.
interval - any kind of timestamp intervalpublic PlainTimestamp getStartAsTimestamp()
Yields the start time point.
null if infiniteBoundary.isInfinite()public LocalDateTime getStartAsLocalDateTime()
Yields the start time point.
null if infiniteBoundary.isInfinite()public PlainTimestamp getEndAsTimestamp()
Yields the end time point.
null if infiniteBoundary.isInfinite()public LocalDateTime getEndAsLocalDateTime()
Yields the end time point.
null if infiniteBoundary.isInfinite()public MomentInterval atUTC()
Combines this local timestamp interval with the timezone offset UTC+00:00 to a global UTC-interval.
at(ZonalOffset)public MomentInterval at(ZonalOffset offset)
Combines this local timestamp interval with given timezone offset to a global UTC-interval.
offset - timezone offsetatUTC(),
inTimezone(TZID)public MomentInterval inStdTimezone()
Combines this local timestamp interval with the system timezone to a global UTC-interval.
Timezone.ofSystem()public MomentInterval inTimezone(TZID tzid)
Combines this local timestamp interval with given timezone to a global UTC-interval.
tzid - timezone idIllegalArgumentException - if given timezone cannot be loadedTimezone.of(TZID),
inStdTimezone(),
GapResolver.NEXT_VALID_TIME,
OverlapResolver.EARLIER_OFFSET@SafeVarargs public final <U extends IsoUnit> Duration<U> getDuration(U... units)
Yields the length of this interval in given units.
U - generic unit typeunits - time units to be used in calculationUnsupportedOperationException - if this interval is infinitepublic Duration<IsoUnit> getDuration(Timezone tz, IsoUnit... units)
Yields the length of this interval in given units and applies a timezone offset correction .
tz - timezoneunits - time units to be used in calculationUnsupportedOperationException - if this interval is infinitepublic TimestampInterval move(long amount, IsoUnit unit)
Moves this interval along the time axis by given units.
amount - amount of unitsunit - time unit for movingpublic Stream<PlainTimestamp> stream(Duration<?> duration)
Obtains a stream iterating over every timestamp which is the result of addition of given duration to start until the end of this interval is reached.
The stream size is limited to Integer.MAX_VALUE - 1 else an ArithmeticException
will be thrown.
duration - duration which has to be added to the start multiple timesIllegalArgumentException - if the duration is not positiveIllegalStateException - if this interval is infinite or if there is no canonical formIsoInterval.toCanonical(),
stream(Duration, PlainTimestamp, PlainTimestamp)public static Stream<PlainTimestamp> stream(Duration<?> duration, PlainTimestamp start, PlainTimestamp end)
Obtains a stream iterating over every timestamp which is the result of addition of given duration to start until the end is reached.
This static method avoids the costs of constructing an instance of TimestampInterval.
The stream size is limited to Integer.MAX_VALUE - 1 else an ArithmeticException
will be thrown.
duration - duration which has to be added to the start multiple timesstart - start boundary - inclusiveend - end boundary - exclusiveIllegalArgumentException - if start is after end or if the duration is not positivepublic Stream<TimestampInterval> streamPartitioned(DayPartitionRule rule)
Creates a partitioning stream of timestamp intervals where every day of this interval is partitioned according to given partitioning rule.
If a day of this interval is not fully defined (concerns only start and end) then it will be intersected with given day partition rule.
rule - day partition ruleIllegalStateException - if this interval is infinite or if there is no canonical formpublic PlainTimestamp random()
IllegalStateException - if this interval is infinite or empty or if there is no canonical formIsoInterval.toCanonical()public String formatISO(IsoDateStyle dateStyle, IsoDecimalStyle decimalStyle, ClockUnit precision, InfinityStyle infinityStyle)
Prints the canonical form of this interval in given ISO-8601 style.
dateStyle - iso-compatible date styledecimalStyle - iso-compatible decimal styleprecision - controls the precision of output format with constant lengthinfinityStyle - controlling the format of infinite boundariesIllegalStateException - if there is no canonical form
or given infinity style prevents infinite intervalsIsoInterval.toCanonical()public String formatReduced(IsoDateStyle dateStyle, IsoDecimalStyle decimalStyle, ClockUnit precision, InfinityStyle infinityStyle)
Prints the canonical form of this interval in given reduced ISO-8601 style.
The term "reduced" means that higher-order elements like the year can be left out in the end component if it is equal to the value of the start component. Example:
TimestampInterval interval =
TimestampInterval.between(
PlainTimestamp.of(2016, 2, 29, 10, 45, 53),
PlainTimestamp.of(2016, 2, 29, 16, 30));
System.out.println(
interval.formatReduced(
IsoDateStyle.EXTENDED_CALENDAR_DATE, IsoDecimalStyle.DOT, ClockUnit.MINUTES, InfinityStyle.SYMBOL));
// Output: 2016-02-29T10:45/T16:30
dateStyle - iso-compatible date styledecimalStyle - iso-compatible decimal styleprecision - controls the precision of output format with constant lengthinfinityStyle - controlling the format of infinite boundariesIllegalStateException - if there is no canonical form
or given infinity style prevents infinite intervalsIsoInterval.toCanonical()public static TimestampInterval parse(String text, ChronoParser<PlainTimestamp> parser) throws ParseException
Interpretes given text as interval using a localized interval pattern.
If given parser does not contain a reference to a locale then the interval pattern "{0}/{1}" will be used.
text - text to be parsedparser - format object for parsing start and end componentsIndexOutOfBoundsException - if given text is emptyParseException - if the text is not parseableparse(String, ChronoParser, String),
FormatPatternProvider.getIntervalPattern(Locale)public static TimestampInterval parse(String text, ChronoParser<PlainTimestamp> parser, String intervalPattern) throws ParseException
Interpretes given text as interval using given interval pattern.
About usage see also DateInterval.parse(String, ChronoParser, String).
text - text to be parsedparser - format object for parsing start and end componentsintervalPattern - interval pattern containing placeholders {0} and {1} (for start and end)IndexOutOfBoundsException - if given text is emptyParseException - if the text is not parseablepublic static TimestampInterval parse(CharSequence text, ChronoParser<PlainTimestamp> parser, BracketPolicy policy) throws ParseException
Interpretes given text as interval.
This method can also accept a hyphen as alternative to solidus as separator between start and end component unless the start component is a period. Infinity symbols are understood.
text - text to be parsedparser - format object for parsing start and end componentspolicy - strategy for parsing interval boundariesParseException - if parsing does not workIndexOutOfBoundsException - if the start position is at end of text or even behindpublic static TimestampInterval parse(CharSequence text, ChronoParser<PlainTimestamp> startFormat, char separator, ChronoParser<PlainTimestamp> endFormat, BracketPolicy policy, ParseLog status)
Interpretes given text as interval.
This method is mainly intended for parsing technical interval formats similar to ISO-8601 which are not localized. Infinity symbols are understood.
text - text to be parsedstartFormat - format object for parsing start componentseparator - char separating start and end componentendFormat - format object for parsing end componentpolicy - strategy for parsing interval boundariesstatus - parser information (always as new instance)null if parsing does not workIndexOutOfBoundsException - if the start position is at end of text or even behindpublic static TimestampInterval parseISO(String text) throws ParseException
Interpretes given ISO-conforming text as interval.
All styles are supported, namely calendar dates, ordinal dates and week dates, either in basic or in extended format. Mixed date styles for start and end are not allowed however. Furthermore, one of start or end can also be represented by a period string. If not then the end component may exist in an abbreviated form as documented in ISO-8601-paper leaving out higher-order elements like the calendar year (which will be overtaken from the start component instead). Infinity symbols are understood as extension although strictly spoken ISO-8601 does not know or specify infinite intervals. Examples for supported formats:
System.out.println(
TimestampInterval.parseISO(
"2012-01-01T14:15/2014-06-20T16:00"));
// output: [2012-01-01T14:15/2014-06-20T16:00)
System.out.println(
TimestampInterval.parseISO(
"2012-01-01T14:15/08-11T16:00"));
// output: [2012-01-01T14:15/2012-08-11T16:00)
System.out.println(
TimestampInterval.parseISO(
"2012-01-01T14:15/16:00"));
// output: [2012-01-01T14:15/2012-01-01T16:00)
System.out.println(
TimestampInterval.parseISO(
"2012-01-01T14:15/P2DT1H45M"));
// output: [2012-01-01T14:15/2012-01-03T16:00)
System.out.println(
TimestampInterval.parseISO(
"2015-01-01T08:45/-"));
// output: [2015-01-01T08:45:00/+∞)
This method dynamically creates an appropriate interval format for reduced forms. If performance is more important then a static fixed formatter might be considered.
text - text to be parsedIndexOutOfBoundsException - if given text is emptyParseException - if the text is not parseableBracketPolicy.SHOW_NEVERCopyright © 2014–2021. All rights reserved.