holidays observed within a single
calendar year. An instance of this class defines the days on which
activities may not occur.- Author:
- Dave Joyce
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateRollDefault 'empty'date rollingbehavior.Defaultdays of weekthat constitute the 'standard' weekend worldwide. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()calculate(int year) Calculate the dates of the holidays on this calendar for the specified year.calculate(int fromYear, int toYear) Calculate the dates of the holidays on this calendar for each year in the specified range, returning all results as a single chronologically- sorted list.calculateByYear(int fromYear, int toYear) Calculate the dates of the holidays on this calendar for each year in the specified range, returning results grouped by year.calculateEarlyCloses(int year) Calculate the dates of the early-close (partial trading day) holidays on this calendar for the specified year.getCode()Get holidays observed on this calendar.getName()Get weekend days recognized by this calendar.booleanDetermine whether this calendar has anyEarlyCloseHolidayentries configured.booleanDetermine if the given instant, in the specified time zone, falls on the weekend as defined by this holiday calendar.booleanDetermine if the given date, in the specified time zone, falls on the weekend as defined by this holiday calendar.booleanisWeekendUTC(Instant instant) Determine if the given instant, in UTC standard time, falls on the weekend as defined by this holiday calendar.booleanisWeekendUTC(Date date) Determine if the given date, in UTC standard time, falls on the weekend as defined by this holiday calendar.merge(HolidayCalendar other) Merge the givenHolidayCalendarobject with this one.toString()
-
Field Details
-
NO_ROLL
Default 'empty'date rollingbehavior. -
STANDARD_WEEKEND
Defaultdays of weekthat constitute the 'standard' weekend worldwide.
-
-
Constructor Details
-
HolidayCalendar
public HolidayCalendar(String code, String name, DateRoll dateRoll, Set<DayOfWeek> weekendDays, Set<Holiday> holidays) Construct a new holiday calendar object.- Parameters:
code- short text code symbol by which this calendar may be locatedname- name of this holiday calendar objectdateRoll- date rolling behavior to be employed by this holiday calendarweekendDays- days of the week to be treated as the weekendholidays- set ofHolidayobjects to be observed
-
-
Method Details
-
builder
-
getCode
-
getName
-
getDateRoll
-
getHolidays
Get holidays observed on this calendar.- Returns:
- unmodifiable set of
Holidayobjects
-
getWeekendDays
Get weekend days recognized by this calendar.- Returns:
- unmodifiable set of weekend
days
-
isWeekend
Determine if the given instant, in the specified time zone, falls on the weekend as defined by this holiday calendar. -
isWeekendUTC
Determine if the given instant, in UTC standard time, falls on the weekend as defined by this holiday calendar. -
isWeekend
Determine if the given date, in the specified time zone, falls on the weekend as defined by this holiday calendar. -
isWeekendUTC
Determine if the given date, in UTC standard time, falls on the weekend as defined by this holiday calendar. -
calculate
Calculate the dates of the holidays on this calendar for the specified year. Thedatesreturned by this method are adjusted according to the date rolling behavior of this calendar.Breaking change (since 2.0.0): this method excludes
EarlyCloseHolidayentries. In 1.x, early-close (half-day) holidays were returned alongside full closures; callers upgrading from 1.x that relied on seeing early closes here must additionally callcalculateEarlyCloses(int). For example, to retrieve both regular and early-close holidays for a year:List<HolidayDate> fullClosures = calendar.calculate(2026); List<HolidayDate> earlyCloses = calendar.calculateEarlyCloses(2026);- Parameters:
year- Common Era (CE) year for which to obtain holiday dates- Returns:
- chronologically-sorted list of observed holiday dates, excluding
EarlyCloseHolidayentries - See Also:
-
calculateEarlyCloses
Calculate the dates of the early-close (partial trading day) holidays on this calendar for the specified year. OnlyEarlyCloseHolidayinstances are considered; these are inherently non-rollable, so no date rolling is applied.Early closes are deliberately excluded from
calculate(int)and are reported exclusively by this method. Each returnedHolidayDatewraps anEarlyCloseHoliday, whoseEarlyCloseHoliday.getCloseTime()andEarlyCloseHoliday.getZoneId()give the local trading-halt time — for example, the ASX (Australia) calendar reports a 14:10Australia/Sydneyclose on Christmas Eve, while NYSE reports a 13:00America/New_Yorkclose on the day after Thanksgiving:for (HolidayDate hd : calendar.calculateEarlyCloses(2026)) { EarlyCloseHoliday h = (EarlyCloseHoliday) hd.holiday(); System.out.printf("%s: %s closes at %s %s%n", hd.getDate(), h.getName(), h.getCloseTime(), h.getZoneId()); }- Parameters:
year- Common Era (CE) year for which to obtain early-close dates- Returns:
- chronologically-sorted list of early-close holiday dates
- See Also:
-
hasEarlyCloses
public boolean hasEarlyCloses()Determine whether this calendar has anyEarlyCloseHolidayentries configured. This is a cheap, year-independent check that lets callers branch without invokingcalculateEarlyCloses(int).- Returns:
trueif this calendar has at least one early-close holiday- See Also:
-
calculate
Calculate the dates of the holidays on this calendar for each year in the specified range, returning all results as a single chronologically- sorted list.The
datesreturned are adjusted according to the date rolling behavior of this calendar. Note that a rolled date may fall outside the nominal year range (e.g. a Dec 31 holiday rolled forward to Jan 1 of the following year).Passing
fromYear == toYearis legal and returns the same result ascalculate(int).- Parameters:
fromYear- first Common Era (CE) year in the range (inclusive)toYear- last Common Era (CE) year in the range (inclusive)- Returns:
- chronologically-sorted list of observed holiday dates across all
years in
[fromYear, toYear] - Throws:
IllegalArgumentException- iffromYear > toYear- See Also:
-
calculateByYear
Calculate the dates of the holidays on this calendar for each year in the specified range, returning results grouped by year.The map contains an entry for every year in
[fromYear, toYear]inclusive — years with no holidays map to an empty list (dense representation). Each list is chronologically sorted. The map itself is ordered by ascending year.Note: the year key is the nominal year used for calculation. A rolled date may have a
HolidayDate.getDate()whose year differs from the map key.Passing
fromYear == toYearis legal.- Parameters:
fromYear- first Common Era (CE) year in the range (inclusive)toYear- last Common Era (CE) year in the range (inclusive)- Returns:
- map of nominal year to chronologically-sorted observed holiday dates, ordered by ascending year; all years in the range are present as keys
- Throws:
IllegalArgumentException- iffromYear > toYear- See Also:
-
merge
Merge the givenHolidayCalendarobject with this one.- Parameters:
other- holiday calendar to be merged- Returns:
- union of this holiday calendar and the specified calendar
-
toString
-