Class CalendarPeriod<T>
- Type Parameters:
T
- generic type of incomplete calendar date (without day part) or dates in other calendar systems
- All Implemented Interfaces:
Serializable
,ChronoInterval<T>
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.
- Since:
- 5.0
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Serves for the creation of generic calendar intervals on a timeline.static class
Serves for parsing of any calendar intervals on a timeline. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
Queries if given time point belongs to this interval.long
delta()
Obtains the delta between start and end in the smallest defined units.boolean
findIntersection(ChronoInterval<T> other)
Obtains the intersection of this interval and other one if present.getEnd()
Yields the upper bound of this interval.getStart()
Yields the lower bound of this interval.int
hashCode()
boolean
Is this interval after the given time point?boolean
isBefore(ChronoInterval<T> other)
Is this interval before the other one?boolean
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>>
CalendarPeriod.Factory<D>on(CalendarFamily<D> family, String variant)
Defines a timeline on which new generic calendar intervals can be created.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.static <U, D extends Calendrical<U, D>>
CalendarPeriod.Factory<D>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>
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.print(ChronoPrinter<T> printer)
Prints this interval using a localized interval pattern.print(ChronoPrinter<T> printer, String intervalPattern)
Prints this interval in a custom format.random()
Obtains a random date within this interval.stream()
Obtains a stream for fixed calendar intervals like years, quarters, months or weeks.toString()
Methods inherited from interface net.time4j.range.ChronoInterval
intersects, isAfter
-
Method Details
-
between
Creates a calendar period for given year range.- Parameters:
y1
- first calendar yeary2
- last calendar year (inclusive)- Returns:
- CalendarPeriod
-
between
Creates a calendar period for given quarter year range.- Parameters:
q1
- first quarter yearq2
- last quarter year (inclusive)- Returns:
- CalendarPeriod
-
between
Creates a calendar period for given month range.- Parameters:
m1
- first calendar monthm2
- last calendar month (inclusive)- Returns:
- CalendarPeriod
-
between
Creates a calendar period for given calendar week range.- Parameters:
w1
- first calendar weekw2
- last calendar week (inclusive)- Returns:
- CalendarPeriod
-
onYears
Defines a parser on which new calendar intervals for years can be created.
- Returns:
- new interval factory intended for parsing
-
onQuarters
Defines a parser on which new calendar intervals for quarters can be created.
- Returns:
- new interval factory intended for parsing
-
onMonths
Defines a parser on which new calendar intervals for months can be created.
- Returns:
- new interval factory intended for parsing
-
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));
- Returns:
- new interval factory intended for parsing
-
on
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]
- Type Parameters:
U
- generic unit typeD
- generic type of timepoints on the underlying timeline- Parameters:
axis
- the calendrical timeline- Returns:
- new interval factory
-
on
public 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.
- Type Parameters:
D
- generic type of timepoints on the underlying timeline- Parameters:
family
- calendar familyvariant
- calendar variant- Returns:
- new interval factory
- See Also:
on(CalendarFamily, VariantSource)
-
on
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.
- Type Parameters:
D
- generic type of timepoints on the underlying timeline- Parameters:
family
- calendar familyvariant
- calendar variant- Returns:
- new interval factory
- See Also:
on(CalendarFamily, String)
-
getStart
Description copied from interface:ChronoInterval
Yields the lower bound of this interval.
- Specified by:
getStart
in interfaceChronoInterval<T>
- Returns:
- start interval boundary
-
getEnd
Description copied from interface:ChronoInterval
Yields the upper bound of this interval.
- Specified by:
getEnd
in interfaceChronoInterval<T>
- Returns:
- end interval boundary
-
isEmpty
public boolean isEmpty()Description copied from interface:ChronoInterval
Determines if this interval is empty.
- Specified by:
isEmpty
in interfaceChronoInterval<T>
- Returns:
true
if this interval does not contain any time point elsefalse
-
isFinite
public boolean isFinite()Description copied from interface:ChronoInterval
Determines if this interval has finite boundaries.
- Specified by:
isFinite
in interfaceChronoInterval<T>
- Returns:
true
if start and end are finite elsefalse
-
contains
Description copied from interface:ChronoInterval
Queries if given time point belongs to this interval.
- Specified by:
contains
in interfaceChronoInterval<T>
- Parameters:
temporal
- time point to be queried- Returns:
true
if given time point belongs to this interval elsefalse
-
contains
Description copied from interface:ChronoInterval
Does 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.
- Specified by:
contains
in interfaceChronoInterval<T>
- Parameters:
other
- another interval whose relation to this interval is to be investigated- Returns:
true
if this interval contains the other one elsefalse
- See Also:
ChronoInterval.intersects(ChronoInterval)
-
isAfter
Description copied from interface:ChronoInterval
Is this interval after the given time point?
- Specified by:
isAfter
in interfaceChronoInterval<T>
- Parameters:
temporal
- reference time point- Returns:
true
if this interval is after given time point elsefalse
-
isBefore
Description copied from interface:ChronoInterval
Is this interval before the given time point?
- Specified by:
isBefore
in interfaceChronoInterval<T>
- Parameters:
temporal
- reference time point- Returns:
true
if this interval is before given time point elsefalse
-
isBefore
Description copied from interface:ChronoInterval
Is this interval before the other one?
- Specified by:
isBefore
in interfaceChronoInterval<T>
- Parameters:
other
- another interval whose relation to this interval is to be investigated- Returns:
true
if this interval is before the other one elsefalse
-
abuts
Description copied from interface:ChronoInterval
Queries if this interval abuts the other one such that there is neither any overlap nor any gap between.
Note: Empty intervals never abut.
- Specified by:
abuts
in interfaceChronoInterval<T>
- Parameters:
other
- another interval which might abut this interval- Returns:
true
if there is no intersection and no gap between elsefalse
-
findIntersection
Obtains the intersection of this interval and other one if present.
- Parameters:
other
- another interval which might have an intersection with this interval- Returns:
- a wrapper around the found intersection or an empty wrapper
- See Also:
Optional.isPresent()
,ChronoInterval.intersects(ChronoInterval)
-
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.- Returns:
- Stream
-
delta
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.
- Returns:
- difference in smallest defined units
- Since:
- 5.0
-
random
Obtains a random date within this interval.
- Returns:
- random date within this interval
-
print
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.
- Parameters:
printer
- format object for printing start and end- Returns:
- localized formatted string
- See Also:
print(ChronoPrinter, String)
,FormatPatternProvider.getIntervalPattern(Locale)
-
print
Prints this interval in a custom format.
- Parameters:
printer
- format object for printing start and end componentsintervalPattern
- interval pattern containing placeholders {0} and {1} (for start and end)- Returns:
- formatted string in given pattern format
-
equals
-
hashCode
public int hashCode() -
toString
-