public final class MomentInterval extends IsoInterval<Moment,MomentInterval> implements Serializable
Defines a moment interval on global timeline.
| Modifier and Type | Field and Description |
|---|---|
static MomentInterval |
ALWAYS
Constant for a moment interval from infinite past to infinite future.
|
static double |
CENTERED
Determines the alignment of surrounding intervals.
|
static double |
LEFT_ALIGNED
Determines the alignment of surrounding intervals.
|
static double |
RIGHT_ALIGNED
Determines the alignment of surrounding intervals.
|
| Modifier and Type | Method and Description |
|---|---|
static MomentInterval |
between(Instant start,
Instant end)
Creates a finite half-open interval between given time points.
|
static MomentInterval |
between(Moment start,
Moment end)
Creates a finite half-open interval between given time points.
|
static Comparator<ChronoInterval<Moment>> |
comparator()
Defines a comparator which sorts intervals first
by start boundary and then by length.
|
String |
formatISO(IsoDateStyle dateStyle,
IsoDecimalStyle decimalStyle,
ClockUnit precision,
ZonalOffset offset,
InfinityStyle infinityStyle)
Prints the canonical form of this interval in given ISO-8601 style.
|
String |
formatReduced(IsoDateStyle dateStyle,
IsoDecimalStyle decimalStyle,
ClockUnit precision,
ZonalOffset offset,
InfinityStyle infinityStyle)
Prints the canonical form of this interval in given reduced ISO-8601 style.
|
static MomentInterval |
from(ChronoInterval<Moment> interval)
Converts an arbitrary moment interval to an interval of this type.
|
Instant |
getEndAsInstant()
Yields the end time point.
|
Moment |
getEndAsMoment()
Yields the end time point.
|
Duration<IsoUnit> |
getNominalDuration(Timezone tz,
IsoUnit... units)
Yields the nominal duration of this interval in given timezone and units.
|
MachineTime<SI> |
getRealDuration()
Yields the length of this interval on the UTC-scale.
|
MachineTime<TimeUnit> |
getSimpleDuration()
Yields the length of this interval on the POSIX-scale.
|
Instant |
getStartAsInstant()
Yields the start time point.
|
Moment |
getStartAsMoment()
Yields the start time point.
|
MomentInterval |
move(long amount,
SI unit)
Moves this interval along the UTC-axis by given SI-units.
|
MomentInterval |
move(long amount,
TimeUnit unit)
Moves this interval along the POSIX-axis by given time units.
|
static MomentInterval |
parse(CharSequence text,
ChronoParser<Moment> parser,
BracketPolicy policy)
Interpretes given text as interval.
|
static MomentInterval |
parse(CharSequence text,
ChronoParser<Moment> parser,
BracketPolicy policy,
ParseLog status)
Deprecated.
Use one of other parse methods accepting a bracket policy instead
|
static MomentInterval |
parse(CharSequence text,
ChronoParser<Moment> startFormat,
char separator,
ChronoParser<Moment> endFormat,
BracketPolicy policy,
ParseLog status)
Interpretes given text as interval.
|
static MomentInterval |
parse(String text,
ChronoParser<Moment> parser)
Interpretes given text as interval using a localized interval pattern.
|
static MomentInterval |
parse(String text,
ChronoParser<Moment> parser,
String intervalPattern)
Interpretes given text as interval using given interval pattern.
|
static MomentInterval |
parseISO(String text)
Interpretes given ISO-conforming text as interval.
|
static MomentInterval |
since(Instant start)
Creates an infinite half-open interval since given start.
|
static MomentInterval |
since(Moment start)
Creates an infinite half-open interval since given start.
|
Stream<Moment> |
stream(MachineTime<?> duration)
Obtains a stream iterating over every moment which is the result of addition of given duration
to start until the end of this interval is reached.
|
static Stream<Moment> |
stream(MachineTime<?> duration,
Moment start,
Moment end)
Obtains a stream iterating over every moment which is the result of addition of given duration
to start until the end is reached.
|
static MomentInterval |
surrounding(Instant instant,
Duration duration,
double alignment)
Creates an interval surrounding given instant.
|
static MomentInterval |
surrounding(Instant instant,
MachineTime<TimeUnit> duration,
double alignment)
|
static MomentInterval |
surrounding(Moment moment,
MachineTime<?> duration,
double alignment)
Creates an interval surrounding given moment.
|
TimestampInterval |
toLocalInterval()
Converts this instance to a local timestamp interval in the system
timezone.
|
TimestampInterval |
toZonalInterval(String tzid)
Converts this instance to a zonal timestamp interval
in given timezone.
|
TimestampInterval |
toZonalInterval(TZID tzid)
Converts this instance to a zonal timestamp interval
in given timezone.
|
static MomentInterval |
until(Instant end)
Creates an infinite open interval until given end.
|
static MomentInterval |
until(Moment end)
Creates an infinite open interval until given end.
|
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, print, startedBy, starts, toCanonical, toString, withClosedEnd, withClosedStart, withEnd, withEnd, withOpenEnd, withOpenStart, withStart, withStart, withValueisFinitepublic static final MomentInterval ALWAYS
public static double LEFT_ALIGNED
surrounding(Moment, MachineTime, double)public static double CENTERED
surrounding(Moment, MachineTime, double)public static double RIGHT_ALIGNED
surrounding(Moment, MachineTime, double)public static Comparator<ChronoInterval<Moment>> 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 MomentInterval between(Moment start, Moment end)
Creates a finite half-open interval between given time points.
start - moment of lower boundary (inclusive)end - moment of upper boundary (exclusive)IllegalArgumentException - if start is after endpublic static MomentInterval between(Instant start, Instant end)
Creates a finite half-open interval between given time points.
start - moment of lower boundary (inclusive)end - moment of upper boundary (exclusive)IllegalArgumentException - if start is after endbetween(Moment, Moment)public static MomentInterval since(Moment start)
Creates an infinite half-open interval since given start.
start - moment of lower boundary (inclusive)public static MomentInterval since(Instant start)
Creates an infinite half-open interval since given start.
start - moment of lower boundary (inclusive)since(Moment)public static MomentInterval until(Moment end)
Creates an infinite open interval until given end.
end - moment of upper boundary (exclusive)public static MomentInterval until(Instant end)
Creates an infinite open interval until given end.
end - moment of upper boundary (exclusive)until(Moment)public static MomentInterval surrounding(Moment moment, MachineTime<?> duration, double alignment)
Creates an interval surrounding given moment.
Alignment:
0.0 then the new interval will start at given moment.0.5 then the new interval will be centered around given moment.1.0 then the new interval will end at given moment.moment - embedded moment at focus of alignmentduration - machine time durationalignment - determines how to align the interval around moment (in range 0.0 <= x <= 1.0)IllegalArgumentException - if the duration is negative or the alignment is not finite or out of rangeUnsupportedOperationException - if any given or calculated moment is before 1972 (only for SI-duration)LEFT_ALIGNED,
CENTERED,
RIGHT_ALIGNEDpublic static MomentInterval surrounding(Instant instant, Duration duration, double alignment)
Creates an interval surrounding given instant.
Equivalent to surrounding(Moment.from(instant), MachineTime.from(duration), alignment).
instant - embedded instant at focus of alignmentduration - machine time durationalignment - determines how to align the interval around instant (in range 0.0 <= x <= 1.0)IllegalArgumentException - if the duration is negative or the alignment is not finite or out of rangeLEFT_ALIGNED,
CENTERED,
RIGHT_ALIGNED@Deprecated public static MomentInterval surrounding(Instant instant, MachineTime<TimeUnit> duration, double alignment)
surrounding(Moment, MachineTime, double)
or surrounding(Instant, java.time.Duration, double)Creates an interval surrounding given instant.
instant - embedded instant at focus of alignmentduration - machine time durationalignment - determines how to align the interval around instant (in range 0.0 <= x <= 1.0)IllegalArgumentException - if the duration is negative or the alignment is not finite or out of rangepublic static MomentInterval from(ChronoInterval<Moment> interval)
Converts an arbitrary moment interval to an interval of this type.
interval - any kind of moment intervalpublic Moment getStartAsMoment()
Yields the start time point.
null if infiniteBoundary.isInfinite()public Instant getStartAsInstant()
Yields the start time point.
Note: Leap seconds will be lost here.
null if infiniteBoundary.isInfinite()public Moment getEndAsMoment()
Yields the end time point.
null if infiniteBoundary.isInfinite()public Instant getEndAsInstant()
Yields the end time point.
Note: Leap seconds will be lost here.
null if infiniteBoundary.isInfinite()public TimestampInterval toLocalInterval()
Converts this instance to a local timestamp interval in the system timezone.
Timezone.ofSystem(),
toZonalInterval(TZID),
toZonalInterval(String)public TimestampInterval toZonalInterval(TZID tzid)
Converts this instance to a zonal timestamp interval in given timezone.
tzid - timezone idIllegalArgumentException - if given timezone cannot be loadedtoLocalInterval()public TimestampInterval toZonalInterval(String tzid)
Converts this instance to a zonal timestamp interval in given timezone.
tzid - timezone idIllegalArgumentException - if given timezone cannot be loadedtoZonalInterval(TZID),
toLocalInterval()public Duration<IsoUnit> getNominalDuration(Timezone tz, IsoUnit... units)
Yields the nominal duration of this interval in given timezone and units.
tz - timezoneunits - time units to be used in calculationUnsupportedOperationException - if this interval is infinitegetSimpleDuration(),
getRealDuration()public MachineTime<TimeUnit> getSimpleDuration()
Yields the length of this interval on the POSIX-scale.
UnsupportedOperationException - if this interval is infinitegetRealDuration()public MachineTime<SI> getRealDuration()
Yields the length of this interval on the UTC-scale.
UnsupportedOperationException - if start is before year 1972
or if this interval is infinitegetSimpleDuration()public MomentInterval move(long amount, TimeUnit unit)
Moves this interval along the POSIX-axis by given time units.
amount - amount of unitsunit - time unit for movingpublic MomentInterval move(long amount, SI unit)
Moves this interval along the UTC-axis by given SI-units.
amount - amount of unitsunit - time unit for movingpublic Stream<Moment> stream(MachineTime<?> duration)
Obtains a stream iterating over every moment 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(MachineTime, Moment, Moment)public static Stream<Moment> stream(MachineTime<?> duration, Moment start, Moment end)
Obtains a stream iterating over every moment 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 MomentInterval.
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 String formatISO(IsoDateStyle dateStyle, IsoDecimalStyle decimalStyle, ClockUnit precision, ZonalOffset offset, 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 lengthoffset - timezone offsetinfinityStyle - 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, ZonalOffset offset, 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. And the offset is never printed in the end component of finite intervals. Example:
MomentInterval interval =
MomentInterval.between(
PlainTimestamp.of(2012, 6, 29, 10, 45),
PlainTimestamp.of(2012, 6, 30, 23, 59, 59).atUTC().plus(1, SI.SECONDS));
System.out.println(
interval.formatReduced(
IsoDateStyle.EXTENDED_CALENDAR_DATE,
IsoDecimalStyle.DOT,
ClockUnit.SECONDS,
ZonalOffset.UTC,
InfinityStyle.SYMBOL));
// Output: 2016-02-29T10:45:00Z/30T23:59:60
dateStyle - iso-compatible date styledecimalStyle - iso-compatible decimal styleprecision - controls the precision of output format with constant lengthoffset - timezone offsetinfinityStyle - controlling the format of infinite boundariesIllegalStateException - if there is no canonical form
or given infinity style prevents infinite intervalsIsoInterval.toCanonical()public static MomentInterval parse(String text, ChronoParser<Moment> 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 MomentInterval parse(String text, ChronoParser<Moment> 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 MomentInterval parse(CharSequence text, ChronoParser<Moment> 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 behind@Deprecated public static MomentInterval parse(CharSequence text, ChronoParser<Moment> parser, BracketPolicy policy, ParseLog status)
Interpretes given text as interval.
Similar to parse(CharSequence, ChronoParser, char, ChronoParser, BracketPolicy, ParseLog).
Since version v3.9/4.6 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.
text - text to be parsedparser - format object for parsing start and end componentspolicy - 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 MomentInterval parse(CharSequence text, ChronoParser<Moment> startFormat, char separator, ChronoParser<Moment> 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 MomentInterval 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). In latter case, the timezone offset of the end component is optional, too. 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(
MomentInterval.parseISO(
"2012-01-01T14:15Z/2014-06-20T16:00Z"));
// output: [2012-01-01T14:15:00Z/2014-06-20T16:00:00Z)
System.out.println(
MomentInterval.parseISO(
"2012-01-01T14:15Z/08-11T16:00+00:01"));
// output: [2012-01-01T14:15:00Z/2012-08-11T15:59:00Z)
System.out.println(
MomentInterval.parseISO(
"2012-01-01T14:15Z/16:00"));
// output: [2012-01-01T14:15:00Z/2012-01-01T16:00:00Z)
System.out.println(
MomentInterval.parseISO(
"2012-01-01T14:15Z/P2DT1H45M"));
// output: [2012-01-01T14:15:00Z/2012-01-03T16:00:00Z)
System.out.println(
MomentInterval.parseISO(
"2015-01-01T08:45Z/-"));
// output: [2015-01-01T08:45:00Z/+∞)
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–2018. All rights reserved.