Class ImmutableHolidayCalendar

  • All Implemented Interfaces:
    HolidayCalendar, Named, Serializable, org.joda.beans.Bean, org.joda.beans.ImmutableBean

    public final class ImmutableHolidayCalendar
    extends Object
    implements HolidayCalendar, org.joda.beans.ImmutableBean, Serializable
    An immutable holiday calendar implementation.

    A standard immutable implementation of HolidayCalendar that stores all dates that are holidays, plus a list of weekend days.

    Internally, the class uses a range to determine the range of known holiday dates. Beyond the range of known holiday dates, weekend days are used to determine business days. Dates may be queried from year zero to year 10,000.

    Applications should refer to holidays using HolidayCalendarId. The identifier must be resolved to a HolidayCalendar before the holiday data methods can be accessed. See HolidayCalendarIds for a standard set of identifiers available in ReferenceData.standard().

    See Also:
    Serialized Form
    • Field Detail

      • DESERIALIZER

        public static final org.joda.beans.ser.SerDeserializer DESERIALIZER
        The deserializer, for compatibility.
    • Method Detail

      • of

        public static ImmutableHolidayCalendar of​(HolidayCalendarId id,
                                                  Iterable<LocalDate> holidays,
                                                  DayOfWeek firstWeekendDay,
                                                  DayOfWeek secondWeekendDay)
        Obtains an instance from a set of holiday dates and weekend days.

        The holiday dates will be extracted into a set with duplicates ignored. The minimum supported date for query is the start of the year of the earliest holiday. The maximum supported date for query is the end of the year of the latest holiday.

        The weekend days may both be the same.

        Parameters:
        id - the identifier
        holidays - the set of holiday dates
        firstWeekendDay - the first weekend day
        secondWeekendDay - the second weekend day, may be same as first
        Returns:
        the holiday calendar
      • of

        public static ImmutableHolidayCalendar of​(HolidayCalendarId id,
                                                  Iterable<LocalDate> holidays,
                                                  Iterable<DayOfWeek> weekendDays)
        Obtains an instance from a set of holiday dates and weekend days.

        The holiday dates will be extracted into a set with duplicates ignored. The minimum supported date for query is the start of the year of the earliest holiday. The maximum supported date for query is the end of the year of the latest holiday.

        The weekend days may be empty, in which case the holiday dates should contain any weekends.

        Parameters:
        id - the identifier
        holidays - the set of holiday dates
        weekendDays - the days that define the weekend, if empty then weekends are treated as business days
        Returns:
        the holiday calendar
      • of

        public static ImmutableHolidayCalendar of​(HolidayCalendarId id,
                                                  Iterable<LocalDate> holidays,
                                                  Iterable<DayOfWeek> weekendDays,
                                                  Iterable<LocalDate> workingDays)
        Obtains an instance from a set of holiday dates and weekend days.

        The holiday dates will be extracted into a set with duplicates ignored. The minimum supported date for query is the start of the year of the earliest holiday. The maximum supported date for query is the end of the year of the latest holiday.

        The weekend days may be empty, in which case the holiday dates should contain any weekends. The working days are processed last, changing holidays and weekends back to business days, but only within the range of supported years.

        Parameters:
        id - the identifier
        holidays - the set of holiday dates
        weekendDays - the days that define the weekend, if empty then weekends are treated as business days
        workingDays - the working days that override holidays and weekends
        Returns:
        the holiday calendar
      • combined

        public static ImmutableHolidayCalendar combined​(ImmutableHolidayCalendar cal1,
                                                        ImmutableHolidayCalendar cal2)
        Obtains a combined holiday calendar instance.

        This combines the two input calendars. It is intended for up-front occasional use rather than continuous use, as it can be relatively slow.

        Parameters:
        cal1 - the first calendar
        cal2 - the second calendar
        Returns:
        the combined calendar
      • shift

        public LocalDate shift​(LocalDate date,
                               int amount)
        Description copied from interface: HolidayCalendar
        Shifts the date by the specified number of business days.

        If the amount is zero, the input date is returned. If the amount is positive, later business days are chosen. If the amount is negative, earlier business days are chosen.

        Specified by:
        shift in interface HolidayCalendar
        Parameters:
        date - the date to adjust
        amount - the number of business days to adjust by
        Returns:
        the shifted date
      • next

        public LocalDate next​(LocalDate date)
        Description copied from interface: HolidayCalendar
        Finds the next business day, always returning a later date.

        Given a date, this method returns the next business day.

        Specified by:
        next in interface HolidayCalendar
        Parameters:
        date - the date to adjust
        Returns:
        the first business day after the input date
      • previous

        public LocalDate previous​(LocalDate date)
        Description copied from interface: HolidayCalendar
        Finds the previous business day, always returning an earlier date.

        Given a date, this method returns the previous business day.

        Specified by:
        previous in interface HolidayCalendar
        Parameters:
        date - the date to adjust
        Returns:
        the first business day before the input date
      • nextSameOrLastInMonth

        public LocalDate nextSameOrLastInMonth​(LocalDate date)
        Description copied from interface: HolidayCalendar
        Finds the next business day within the month, returning the input date if it is a business day, or the last business day of the month if the next business day is in a different month.

        Given a date, this method returns a business day. If the input date is a business day, it is returned. If the next business day is within the same month, it is returned. Otherwise, the last business day of the month is returned.

        Note that the result of this method may be earlier than the input date.

        This corresponds to the modified following business day convention.

        Specified by:
        nextSameOrLastInMonth in interface HolidayCalendar
        Parameters:
        date - the date to adjust
        Returns:
        the input date if it is a business day, the next business day if within the same month or the last business day of the month
      • isLastBusinessDayOfMonth

        public boolean isLastBusinessDayOfMonth​(LocalDate date)
        Description copied from interface: HolidayCalendar
        Checks if the specified date is the last business day of the month.

        This returns true if the date specified is the last valid business day of the month.

        Specified by:
        isLastBusinessDayOfMonth in interface HolidayCalendar
        Parameters:
        date - the date to check
        Returns:
        true if the specified date is the last business day of the month
      • lastBusinessDayOfMonth

        public LocalDate lastBusinessDayOfMonth​(LocalDate date)
        Description copied from interface: HolidayCalendar
        Calculates the last business day of the month.

        Given a date, this method returns the date of the last business day of the month.

        Specified by:
        lastBusinessDayOfMonth in interface HolidayCalendar
        Parameters:
        date - the date to check
        Returns:
        the date of the last business day of the month
      • daysBetween

        public int daysBetween​(LocalDate startInclusive,
                               LocalDate endExclusive)
        Description copied from interface: HolidayCalendar
        Calculates the number of business days between two dates.

        This calculates the number of business days within the range. If the dates are equal, zero is returned. If the end is before the start, an exception is thrown.

        Specified by:
        daysBetween in interface HolidayCalendar
        Parameters:
        startInclusive - the start date
        endExclusive - the end date
        Returns:
        the total number of business days between the start and end date
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public String toString()
        Returns the name of the calendar.
        Overrides:
        toString in class Object
        Returns:
        the descriptive string