Class ClockInterval
- All Implemented Interfaces:
Serializable
,ChronoInterval<PlainTime>
Defines a finite wall time interval on the local timeline.
- Since:
- 2.0
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Field Summary
Modifier and TypeFieldDescriptionstatic ClockInterval
Represents the full day from 00:00 inclusive to 24:00 exclusive. -
Method Summary
Modifier and TypeMethodDescriptionstatic ClockInterval
Creates a finite half-open interval between given wall times.static ClockInterval
Creates a finite half-open interval between given wall times.static Comparator<ChronoInterval<PlainTime>>
Defines a comparator which sorts intervals first by start boundary and then by length.formatBasicISO(IsoDecimalStyle decimalStyle, ClockUnit precision)
Prints the canonical form of this interval in given basic ISO-8601 style.formatExtendedISO(IsoDecimalStyle decimalStyle, ClockUnit precision)
Prints the canonical form of this interval in given extended ISO-8601 style.static ClockInterval
from(ChronoInterval<PlainTime> interval)
Converts an arbitrary clock interval to an interval of this type.Yields the length of this interval.Yields the end time point.Yields the end time point.Yields the start time point.Yields the start time point.Moves this interval along the time axis by given units.Creates a timestamp interval for given calendar date based on this clock interval.static ClockInterval
parse(CharSequence text, ChronoParser<PlainTime> startFormat, char separator, ChronoParser<PlainTime> endFormat, BracketPolicy policy, ParseLog status)
Interpretes given text as interval.static ClockInterval
parse(CharSequence text, ChronoParser<PlainTime> parser, BracketPolicy policy)
Interpretes given text as interval.static ClockInterval
parse(String text, ChronoParser<PlainTime> parser)
Interpretes given text as interval using a localized interval pattern.static ClockInterval
parse(String text, ChronoParser<PlainTime> parser, String intervalPattern)
Interpretes given text as interval using given interval pattern.static ClockInterval
Interpretes given ISO-conforming text as interval.random()
Obtains a random time within this interval.static ClockInterval
Creates a finite half-open interval between given start time and midnight at end of day (exclusive).static ClockInterval
Creates a finite half-open interval between given start time and midnight at end of day (exclusive).Obtains a stream iterating over every clock time which is the result of addition of given duration to start until the end of this interval is reached.Obtains a stream iterating over every clock time which is the result of addition of given duration to start until the end is reached.static ClockInterval
Creates a finite half-open interval between midnight at start of day and given end time.static ClockInterval
Creates a finite half-open interval between midnight at start of day and given end time.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
-
FULL_DAY
Represents the full day from 00:00 inclusive to 24:00 exclusive.
- Since:
- 5.4
-
-
Method Details
-
comparator
Defines a comparator which sorts intervals first by start boundary and then by length.
- Returns:
- Comparator
- Since:
- 2.0
-
between
Creates a finite half-open interval between given wall times.
- Parameters:
start
- time of lower boundary (inclusive)end
- time of upper boundary (exclusive)- Returns:
- new time interval
- Throws:
IllegalArgumentException
- if start is after end- Since:
- 2.0
-
between
Creates a finite half-open interval between given wall times.
For better handling of time 24:00, it is recommended to directly use the overloaded variant with arguments of type
PlainTime
.- Parameters:
start
- time of lower boundary (inclusive)end
- time of upper boundary (exclusive)- Returns:
- new time interval
- Throws:
IllegalArgumentException
- if start is after end- Since:
- 4.11
- See Also:
between(PlainTime, PlainTime)
-
since
Creates a finite half-open interval between given start time and midnight at end of day (exclusive).
Note: The special wall time 24:00 does not belong to the created interval.
- Parameters:
start
- time of lower boundary (inclusive)- Returns:
- new time interval
- Since:
- 2.0
-
since
Creates a finite half-open interval between given start time and midnight at end of day (exclusive).
- Parameters:
start
- time of lower boundary (inclusive)- Returns:
- new time interval
- Since:
- 4.11
- See Also:
since(PlainTime)
-
until
Creates a finite half-open interval between midnight at start of day and given end time.
- Parameters:
end
- time of upper boundary (exclusive)- Returns:
- new time interval
- Since:
- 2.0
-
until
Creates a finite half-open interval between midnight at start of day and given end time.
- Parameters:
end
- time of upper boundary (exclusive)- Returns:
- new time interval
- Since:
- 4.11
- See Also:
until(PlainTime)
-
from
Converts an arbitrary clock interval to an interval of this type.
- Parameters:
interval
- any kind of clock interval- Returns:
- ClockInterval
- Since:
- 3.34/4.29
-
on
Creates a timestamp interval for given calendar date based on this clock interval.
- Parameters:
date
- gregorian calendar date- Returns:
- new timestamp interval
- Since:
- 5.0
-
getStartAsClockTime
Yields the start time point.
- Returns:
- start time point
- Since:
- 4.11
-
getStartAsLocalTime
Yields the start time point.
- Returns:
- start time point
- Since:
- 4.11
-
getEndAsClockTime
Yields the end time point.
- Returns:
- end time point
- Since:
- 4.11
-
getEndAsLocalTime
Yields the end time point.
The end time 24:00 (midnight at end of day) will be mapped to midnight at start of next day (00:00).
- Returns:
- end time point
- Since:
- 4.11
-
getDuration
Yields the length of this interval.
- Returns:
- duration in hours, minutes, seconds and nanoseconds
- 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 clock time 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 clock times which are the result of adding the duration to the start
- Throws:
IllegalArgumentException
- if the duration is not positiveIllegalStateException
- if this interval has no canonical form- Since:
- 4.18
- See Also:
IsoInterval.toCanonical()
,stream(Duration, PlainTime, PlainTime)
-
stream
public static Stream<PlainTime> stream(Duration<ClockUnit> duration, PlainTime start, PlainTime end)Obtains a stream iterating over every clock time 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
ClockInterval
. 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 clock times 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
-
random
Obtains a random time within this interval.
- Returns:
- random time within this interval
- Throws:
IllegalStateException
- if this interval is empty or if there is no canonical form- Since:
- 5.0
- See Also:
IsoInterval.toCanonical()
-
formatBasicISO
Prints the canonical form of this interval in given basic ISO-8601 style.
- Parameters:
decimalStyle
- iso-compatible decimal styleprecision
- controls the precision of output format with constant length- Returns:
- String
- Throws:
IllegalStateException
- if there is no canonical form (for example for [00:00/24:00])- Since:
- 4.18
- See Also:
IsoInterval.toCanonical()
-
formatExtendedISO
Prints the canonical form of this interval in given extended ISO-8601 style.
- Parameters:
decimalStyle
- iso-compatible decimal styleprecision
- controls the precision of output format with constant length- Returns:
- String
- Throws:
IllegalStateException
- if there is no canonical form (for example for [00:00/24:00])- Since:
- 4.18
- See Also:
IsoInterval.toCanonical()
-
parse
public static ClockInterval parse(String text, ChronoParser<PlainTime> 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 ClockInterval parse(String text, ChronoParser<PlainTime> 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 ClockInterval parse(CharSequence text, ChronoParser<PlainTime> 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.
- 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 ClockInterval parse(CharSequence text, ChronoParser<PlainTime> startFormat, char separator, ChronoParser<PlainTime> 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.
- 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.
Examples for supported formats:
- 09:45/PT5H
- PT5H/14:45
- 0945/PT5H
- PT5H/1445
- PT01:55:30/14:15:30
- 04:01:30.123/24:00:00.000
- 04:01:30,123/24:00:00,000
- Parameters:
text
- text to be parsed- Returns:
- parsed interval
- Throws:
IndexOutOfBoundsException
- if given text is emptyParseException
- if the text is not parseable- Since:
- 2.1
- See Also:
BracketPolicy.SHOW_NEVER
-