T - generic type of incomplete calendar date (without day part) or dates in other calendar systemspublic class CalendarPeriod<T> extends Object implements ChronoInterval<T>, Serializable
Represents a closed interval between two incomplete calendar dates like months, weeks, quarters or years.
This class can also represent generic intervals using different calendar systems.
| Modifier and Type | Class and Description |
|---|---|
static class |
CalendarPeriod.Factory<T>
Serves for the creation of generic calendar intervals on a timeline.
|
static class |
CalendarPeriod.Parser<T>
Serves for parsing of any calendar intervals on a timeline.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
abuts(ChronoInterval<T> other)
Queries if this interval abuts the other one such that there is neither any overlap nor any gap between.
|
static CalendarPeriod<CalendarMonth> |
between(CalendarMonth m1,
CalendarMonth m2)
Creates a calendar period for given month range.
|
static CalendarPeriod<CalendarQuarter> |
between(CalendarQuarter q1,
CalendarQuarter q2)
Creates a calendar period for given quarter year range.
|
static CalendarPeriod<CalendarWeek> |
between(CalendarWeek w1,
CalendarWeek w2)
Creates a calendar period for given calendar week range.
|
static CalendarPeriod<CalendarYear> |
between(CalendarYear y1,
CalendarYear y2)
Creates a calendar period for given year range.
|
boolean |
contains(ChronoInterval<T> other)
Does this interval contain the other one?
|
boolean |
contains(T temporal)
Queries if given time point belongs to this interval.
|
long |
delta()
Obtains the delta between start and end in the smallest defined units.
|
boolean |
equals(Object obj) |
Optional<CalendarPeriod<T>> |
findIntersection(ChronoInterval<T> other)
Obtains the intersection of this interval and other one if present.
|
Boundary<T> |
getEnd()
Yields the upper bound of this interval.
|
Boundary<T> |
getStart()
Yields the lower bound of this interval.
|
int |
hashCode() |
boolean |
isAfter(T temporal)
Is this interval after the given time point?
|
boolean |
isBefore(ChronoInterval<T> other)
Is this interval before the other one?
|
boolean |
isBefore(T temporal)
Is this interval before the given time point?
|
boolean |
isEmpty()
Determines if this interval is empty.
|
boolean |
isFinite()
Determines if this interval has finite boundaries.
|
static <D extends CalendarVariant<D>> |
on(CalendarFamily<D> family,
String variant)
Defines a timeline on which new generic calendar intervals can be created.
|
static <D extends CalendarVariant<D>> |
on(CalendarFamily<D> family,
VariantSource variant)
Defines a timeline on which new generic calendar intervals can be created.
|
static <U,D extends Calendrical<U,D>> |
on(TimeAxis<U,D> axis)
Defines a timeline on which new generic calendar intervals can be created.
|
static CalendarPeriod.Parser<CalendarMonth> |
onMonths()
Defines a parser on which new calendar intervals for months can be created.
|
static CalendarPeriod.Parser<CalendarQuarter> |
onQuarters()
Defines a parser on which new calendar intervals for quarters can be created.
|
static CalendarPeriod.Parser<CalendarWeek> |
onWeeks()
Defines a parser on which new calendar intervals for weeks can be created.
|
static CalendarPeriod.Parser<CalendarYear> |
onYears()
Defines a parser on which new calendar intervals for years can be created.
|
String |
print(ChronoPrinter<T> printer)
Prints this interval using a localized interval pattern.
|
String |
print(ChronoPrinter<T> printer,
String intervalPattern)
Prints this interval in a custom format.
|
T |
random()
Obtains a random date within this interval.
|
Stream<T> |
stream()
Obtains a stream for fixed calendar intervals like years, quarters, months or weeks.
|
String |
toString() |
intersects, isAfterpublic static CalendarPeriod<CalendarYear> between(CalendarYear y1, CalendarYear y2)
y1 - first calendar yeary2 - last calendar year (inclusive)public static CalendarPeriod<CalendarQuarter> between(CalendarQuarter q1, CalendarQuarter q2)
q1 - first quarter yearq2 - last quarter year (inclusive)public static CalendarPeriod<CalendarMonth> between(CalendarMonth m1, CalendarMonth m2)
m1 - first calendar monthm2 - last calendar month (inclusive)public static CalendarPeriod<CalendarWeek> between(CalendarWeek w1, CalendarWeek w2)
w1 - first calendar weekw2 - last calendar week (inclusive)public static CalendarPeriod.Parser<CalendarYear> onYears()
Defines a parser on which new calendar intervals for years can be created.
public static CalendarPeriod.Parser<CalendarQuarter> onQuarters()
Defines a parser on which new calendar intervals for quarters can be created.
public static CalendarPeriod.Parser<CalendarMonth> onMonths()
Defines a parser on which new calendar intervals for months can be created.
public static CalendarPeriod.Parser<CalendarWeek> onWeeks()
Defines a parser on which new calendar intervals for weeks can be created.
Important: Use the root locale to make sure that the parser will use the ISO-8601-definition of a calendar week. Example:
CalendarPeriod<CalendarWeek> expected =
CalendarPeriod.between(
CalendarWeek.of(2017, 52),
CalendarWeek.of(2020, 4));
ChronoFormatter<CalendarWeek> f =
ChronoFormatter.ofPattern( // use root locale for getting the week of year as ISO-week
"w. 'week of' YYYY", PatternType.CLDR, Locale.ROOT, CalendarWeek.chronology());
assertThat(CalendarPeriod.onWeeks().parse("52. week of 2017 – 4. week of 2020", f), is(expected));
public static <U,D extends Calendrical<U,D>> CalendarPeriod.Factory<D> on(TimeAxis<U,D> axis)
Defines a timeline on which new generic calendar intervals can be created.
Example:
PersianCalendar start = PersianCalendar.of(1392, PersianMonth.ESFAND, 27);
PersianCalendar end = PersianCalendar.of(1393, PersianMonth.FARVARDIN, 6);
CalendarPeriod<PersianCalendar> i1 =
CalendarPeriod.on(PersianCalendar.axis()).between(start, end);
CalendarPeriod<PersianCalendar> i2 =
CalendarPeriod.on(PersianCalendar.axis()).between(
end.minus(CalendarDays.ONE),
end.plus(CalendarDays.ONE));
System.out.println(
interval.findIntersection(
CalendarPeriod.on(PersianCalendar.axis()).between(
end.minus(CalendarDays.ONE), end.plus(CalendarDays.ONE))).get());
// [AP-1393-01-05/AP-1393-01-06]
D - generic type of timepoints on the underlying timelineaxis - the calendrical timelinepublic static <D extends CalendarVariant<D>> CalendarPeriod.Factory<D> on(CalendarFamily<D> family, String variant)
Defines a timeline on which new generic calendar intervals can be created.
D - generic type of timepoints on the underlying timelinefamily - calendar familyvariant - calendar varianton(CalendarFamily, VariantSource)public static <D extends CalendarVariant<D>> CalendarPeriod.Factory<D> on(CalendarFamily<D> family, VariantSource variant)
Defines a timeline on which new generic calendar intervals can be created.
D - generic type of timepoints on the underlying timelinefamily - calendar familyvariant - calendar varianton(CalendarFamily, String)public Boundary<T> getStart()
ChronoIntervalYields the lower bound of this interval.
getStart in interface ChronoInterval<T>public Boundary<T> getEnd()
ChronoIntervalYields the upper bound of this interval.
getEnd in interface ChronoInterval<T>public boolean isEmpty()
ChronoIntervalDetermines if this interval is empty.
isEmpty in interface ChronoInterval<T>true if this interval does not contain any time point else falsepublic boolean isFinite()
ChronoIntervalDetermines if this interval has finite boundaries.
isFinite in interface ChronoInterval<T>true if start and end are finite else falsepublic boolean contains(T temporal)
ChronoIntervalQueries if given time point belongs to this interval.
contains in interface ChronoInterval<T>temporal - time point to be queriedtrue if given time point belongs to this interval else falsepublic boolean contains(ChronoInterval<T> other)
ChronoIntervalDoes this interval contain the other one?
An interval cannot contain infinite intervals but can contain an empty interval if it contains the start anchor of the empty interval.
contains in interface ChronoInterval<T>other - another interval whose relation to this interval is to be investigatedtrue if this interval contains the other one else falseChronoInterval.intersects(ChronoInterval)public boolean isAfter(T temporal)
ChronoIntervalIs this interval after the given time point?
isAfter in interface ChronoInterval<T>temporal - reference time pointtrue if this interval is after given time point else falsepublic boolean isBefore(T temporal)
ChronoIntervalIs this interval before the given time point?
isBefore in interface ChronoInterval<T>temporal - reference time pointtrue if this interval is before given time point else falsepublic boolean isBefore(ChronoInterval<T> other)
ChronoIntervalIs this interval before the other one?
isBefore in interface ChronoInterval<T>other - another interval whose relation to this interval is to be investigatedtrue if this interval is before the other one else falsepublic boolean abuts(ChronoInterval<T> other)
ChronoIntervalQueries if this interval abuts the other one such that there is neither any overlap nor any gap between.
Note: Empty intervals never abut.
abuts in interface ChronoInterval<T>other - another interval which might abut this intervaltrue if there is no intersection and no gap between else falsepublic Optional<CalendarPeriod<T>> findIntersection(ChronoInterval<T> other)
Obtains the intersection of this interval and other one if present.
other - another interval which might have an intersection with this intervalOptional.isPresent(),
ChronoInterval.intersects(ChronoInterval)public Stream<T> stream()
Obtains a stream for fixed calendar intervals like years, quarters, months or weeks.
The produced stream has at least one element and is always finite. If it was produced by mean of
on(...).between(...) then the step width is one calendar day.
public long delta()
Obtains the delta between start and end in the smallest defined units.
If start and end are equal then the delta is zero.
public T random()
public String print(ChronoPrinter<T> printer)
Prints this interval using a localized interval pattern.
If given printer does not contain a reference to a locale then the interval pattern "{0}/{1}" will be used.
printer - format object for printing start and endprint(ChronoPrinter, String),
FormatPatternProvider.getIntervalPattern(Locale)public String print(ChronoPrinter<T> printer, String intervalPattern)
Prints this interval in a custom format.
printer - format object for printing start and end componentsintervalPattern - interval pattern containing placeholders {0} and {1} (for start and end)Copyright © 2014–2021. All rights reserved.