Class TimestampInterval
- All Implemented Interfaces:
Serializable
,ChronoInterval<PlainTimestamp>
Defines a timestamp interval on local timeline.
- Since:
- 2.0
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Field Summary
Modifier and TypeFieldDescriptionstatic TimestampInterval
Constant for a timestamp interval from infinite past to infinite future. -
Method Summary
Modifier and TypeMethodDescriptionat(ZonalOffset offset)
Combines this local timestamp interval with given timezone offset to a global UTC-interval.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>>
Defines a comparator which sorts intervals first by start boundary and then by length.formatISO(IsoDateStyle dateStyle, IsoDecimalStyle decimalStyle, ClockUnit precision, InfinityStyle infinityStyle)
Prints the canonical form of this interval in given ISO-8601 style.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.getDuration(Timezone tz, IsoUnit... units)
Yields the length of this interval in given units and applies a timezone offset correction .getDuration(U... units)
Yields the length of this interval in given units.Yields the end time point.Yields the end time point.Yields the start time point.Yields the start time point.Combines this local timestamp interval with the system timezone to a global UTC-interval.inTimezone(TZID tzid)
Combines this local timestamp interval with given timezone to a global UTC-interval.Moves this interval along the time axis by given units.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(CharSequence text, ChronoParser<PlainTimestamp> parser, BracketPolicy policy)
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
Interpretes given ISO-conforming text as interval.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.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.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.Methods inherited from class net.time4j.range.IsoInterval
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, withValue
Methods inherited from interface net.time4j.range.ChronoInterval
isFinite
-
Field Details
-
ALWAYS
Constant for a timestamp interval from infinite past to infinite future.- Since:
- 3.36/4.31
-
-
Method Details
-
comparator
Defines a comparator which sorts intervals first by start boundary and then by length.
- Returns:
- Comparator
- Throws:
IllegalArgumentException
- if applied on intervals which have boundaries with extreme values- Since:
- 2.0
-
between
Creates a finite half-open interval between given time points.
- Parameters:
start
- timestamp of lower boundary (inclusive)end
- timestamp of upper boundary (exclusive)- Returns:
- new timestamp interval
- Throws:
IllegalArgumentException
- if start is after end- Since:
- 2.0
-
between
Creates a finite half-open interval between given time points.
- Parameters:
start
- timestamp of lower boundary (inclusive)end
- timestamp of upper boundary (exclusive)- Returns:
- new timestamp interval
- Throws:
IllegalArgumentException
- if start is after end- Since:
- 4.11
- See Also:
between(PlainTimestamp, PlainTimestamp)
-
since
Creates an infinite half-open interval since given start timestamp.
- Parameters:
start
- timestamp of lower boundary (inclusive)- Returns:
- new timestamp interval
- Since:
- 2.0
-
since
Creates an infinite half-open interval since given start timestamp.
- Parameters:
start
- timestamp of lower boundary (inclusive)- Returns:
- new timestamp interval
- Since:
- 4.11
- See Also:
since(PlainTimestamp)
-
until
Creates an infinite open interval until given end timestamp.
- Parameters:
end
- timestamp of upper boundary (exclusive)- Returns:
- new timestamp interval
- Since:
- 2.0
-
until
Creates an infinite open interval until given end timestamp.
- Parameters:
end
- timestamp of upper boundary (exclusive)- Returns:
- new timestamp interval
- Since:
- 4.11
- See Also:
until(PlainTimestamp)
-
from
Converts an arbitrary timestamp interval to an interval of this type.
- Parameters:
interval
- any kind of timestamp interval- Returns:
- TimestampInterval
- Since:
- 3.34/4.29
-
getStartAsTimestamp
Yields the start time point.
- Returns:
- start time point or
null
if infinite - Since:
- 4.11
- See Also:
Boundary.isInfinite()
-
getStartAsLocalDateTime
Yields the start time point.
- Returns:
- start time point or
null
if infinite - Since:
- 4.11
- See Also:
Boundary.isInfinite()
-
getEndAsTimestamp
Yields the end time point.
- Returns:
- end time point or
null
if infinite - Since:
- 4.11
- See Also:
Boundary.isInfinite()
-
getEndAsLocalDateTime
Yields the end time point.
- Returns:
- end time point or
null
if infinite - Since:
- 4.11
- See Also:
Boundary.isInfinite()
-
atUTC
Combines this local timestamp interval with the timezone offset UTC+00:00 to a global UTC-interval.
- Returns:
- global timestamp interval interpreted at offset UTC+00:00
- Since:
- 2.0
- See Also:
at(ZonalOffset)
-
at
Combines this local timestamp interval with given timezone offset to a global UTC-interval.
- Parameters:
offset
- timezone offset- Returns:
- global timestamp interval interpreted at given offset
- Since:
- 2.0
- See Also:
atUTC()
,inTimezone(TZID)
-
inStdTimezone
Combines this local timestamp interval with the system timezone to a global UTC-interval.
- Returns:
- global timestamp interval interpreted in system timezone
- Since:
- 2.0
- See Also:
Timezone.ofSystem()
-
inTimezone
Combines this local timestamp interval with given timezone to a global UTC-interval.
- Parameters:
tzid
- timezone id- Returns:
- global timestamp interval interpreted in given timezone
- Throws:
IllegalArgumentException
- if given timezone cannot be loaded- Since:
- 2.0
- See Also:
Timezone.of(TZID)
,inStdTimezone()
,GapResolver.NEXT_VALID_TIME
,OverlapResolver.EARLIER_OFFSET
-
getDuration
Yields the length of this interval in given units.
- Type Parameters:
U
- generic unit type- Parameters:
units
- time units to be used in calculation- Returns:
- duration in given units
- Throws:
UnsupportedOperationException
- if this interval is infinite- Since:
- 2.0
-
getDuration
Yields the length of this interval in given units and applies a timezone offset correction .
- Parameters:
tz
- timezoneunits
- time units to be used in calculation- Returns:
- duration in given units including a zonal correction
- Throws:
UnsupportedOperationException
- if this interval is infinite- Since:
- 2.0
-
move
Moves this interval along the time axis by given units.
- Parameters:
amount
- amount of unitsunit
- time unit for moving- Returns:
- moved copy of this interval
-
stream
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 anArithmeticException
will be thrown.- Parameters:
duration
- duration which has to be added to the start multiple times- Returns:
- stream consisting of distinct timestamps which are the result of adding the duration to the start
- Throws:
IllegalArgumentException
- if the duration is not positiveIllegalStateException
- if this interval is infinite or if there is no canonical form- Since:
- 4.18
- See Also:
IsoInterval.toCanonical()
,stream(Duration, PlainTimestamp, PlainTimestamp)
-
stream
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 toInteger.MAX_VALUE - 1
else anArithmeticException
will be thrown.- Parameters:
duration
- duration which has to be added to the start multiple timesstart
- start boundary - inclusiveend
- end boundary - exclusive- Returns:
- stream consisting of distinct timestamps which are the result of adding the duration to the start
- Throws:
IllegalArgumentException
- if start is after end or if the duration is not positive- Since:
- 4.18
-
streamPartitioned
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.
- Parameters:
rule
- day partition rule- Returns:
- stream of timestamp intervals
- Throws:
IllegalStateException
- if this interval is infinite or if there is no canonical form- Since:
- 5.0
-
random
Obtains a random timestamp within this interval.
- Returns:
- random timestamp within this interval
- Throws:
IllegalStateException
- if this interval is infinite or empty or if there is no canonical form- Since:
- 5.0
- See Also:
IsoInterval.toCanonical()
-
formatISO
public String formatISO(IsoDateStyle dateStyle, IsoDecimalStyle decimalStyle, ClockUnit precision, InfinityStyle infinityStyle)Prints the canonical form of this interval in given ISO-8601 style.
- Parameters:
dateStyle
- iso-compatible date styledecimalStyle
- iso-compatible decimal styleprecision
- controls the precision of output format with constant lengthinfinityStyle
- controlling the format of infinite boundaries- Returns:
- String
- Throws:
IllegalStateException
- if there is no canonical form or given infinity style prevents infinite intervals- Since:
- 4.18
- See Also:
IsoInterval.toCanonical()
-
formatReduced
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
- Parameters:
dateStyle
- iso-compatible date styledecimalStyle
- iso-compatible decimal styleprecision
- controls the precision of output format with constant lengthinfinityStyle
- controlling the format of infinite boundaries- Returns:
- String
- Throws:
IllegalStateException
- if there is no canonical form or given infinity style prevents infinite intervals- Since:
- 4.18
- See Also:
IsoInterval.toCanonical()
-
parse
public static TimestampInterval parse(String text, ChronoParser<PlainTimestamp> parser) throws ParseExceptionInterpretes 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.
- Parameters:
text
- text to be parsedparser
- format object for parsing start and end components- Returns:
- parsed interval
- Throws:
IndexOutOfBoundsException
- if given text is emptyParseException
- if the text is not parseable- Since:
- 3.9/4.6
- See Also:
parse(String, ChronoParser, String)
,FormatPatternProvider.getIntervalPattern(Locale)
-
parse
public static TimestampInterval parse(String text, ChronoParser<PlainTimestamp> parser, String intervalPattern) throws ParseExceptionInterpretes given text as interval using given interval pattern.
About usage see also
DateInterval.parse(String, ChronoParser, String)
.- Parameters:
text
- text to be parsedparser
- format object for parsing start and end componentsintervalPattern
- interval pattern containing placeholders {0} and {1} (for start and end)- Returns:
- parsed interval
- Throws:
IndexOutOfBoundsException
- if given text is emptyParseException
- if the text is not parseable- Since:
- 3.9/4.6
-
parse
public static TimestampInterval parse(CharSequence text, ChronoParser<PlainTimestamp> parser, BracketPolicy policy) throws ParseExceptionInterpretes 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.
- Parameters:
text
- text to be parsedparser
- format object for parsing start and end componentspolicy
- strategy for parsing interval boundaries- Returns:
- result
- Throws:
ParseException
- if parsing does not workIndexOutOfBoundsException
- if the start position is at end of text or even behind- Since:
- 4.18
-
parse
public 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.
- Parameters:
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)- Returns:
- result or
null
if parsing does not work - Throws:
IndexOutOfBoundsException
- if the start position is at end of text or even behind- Since:
- 3.9/4.6
-
parseISO
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.
- Parameters:
text
- text to be parsed- Returns:
- parsed interval
- Throws:
IndexOutOfBoundsException
- if given text is emptyParseException
- if the text is not parseable- Since:
- 2.0
- See Also:
BracketPolicy.SHOW_NEVER
-