public final class MomentInterval extends IsoInterval<Moment,MomentInterval> implements Serializable
Defines a moment interval on global timeline.
| 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.
|
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.
|
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 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 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 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–2017. All rights reserved.