Interface HolidayCalendar

  • All Superinterfaces:
    Named
    All Known Implementing Classes:
    ImmutableHolidayCalendar

    public interface HolidayCalendar
    extends Named
    A holiday calendar, classifying dates as holidays or business days.

    Many calculations in finance require knowledge of whether a date is a business day or not. This class encapsulates that knowledge, with each day treated as a holiday or a business day. Weekends are effectively treated as a special kind of holiday.

    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().

    All implementations of this interface must be immutable and thread-safe.

    See Also:
    ImmutableHolidayCalendar
    • Method Detail

      • isHoliday

        boolean isHoliday​(LocalDate date)
        Checks if the specified date is a holiday.

        This is the opposite of isBusinessDay(LocalDate). A weekend is treated as a holiday.

        Parameters:
        date - the date to check
        Returns:
        true if the specified date is a holiday
        Throws:
        IllegalArgumentException - if the date is outside the supported range
      • isBusinessDay

        default boolean isBusinessDay​(LocalDate date)
        Checks if the specified date is a business day.

        This is the opposite of isHoliday(LocalDate). A weekend is treated as a holiday.

        Parameters:
        date - the date to check
        Returns:
        true if the specified date is a business day
        Throws:
        IllegalArgumentException - if the date is outside the supported range
      • adjustBy

        default TemporalAdjuster adjustBy​(int amount)
        Returns an adjuster that changes the date.

        The adjuster is intended to be used with the method Temporal.with(TemporalAdjuster). For example:

         threeDaysLater = date.with(businessDays.adjustBy(3));
         twoDaysEarlier = date.with(businessDays.adjustBy(-2));
         
        Parameters:
        amount - the number of business days to adjust by
        Returns:
        the first business day after this one
        Throws:
        IllegalArgumentException - if the calculation is outside the supported range
      • shift

        default LocalDate shift​(LocalDate date,
                                int amount)
        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.

        Parameters:
        date - the date to adjust
        amount - the number of business days to adjust by
        Returns:
        the shifted date
        Throws:
        IllegalArgumentException - if the calculation is outside the supported range
      • next

        default LocalDate next​(LocalDate date)
        Finds the next business day, always returning a later date.

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

        Parameters:
        date - the date to adjust
        Returns:
        the first business day after the input date
        Throws:
        IllegalArgumentException - if the calculation is outside the supported range
      • nextOrSame

        default LocalDate nextOrSame​(LocalDate date)
        Finds the next business day, returning the input date if it is a business day.

        Given a date, this method returns a business day. If the input date is a business day, it is returned. Otherwise, the next business day is returned.

        Parameters:
        date - the date to adjust
        Returns:
        the input date if it is a business day, or the next business day
        Throws:
        IllegalArgumentException - if the calculation is outside the supported range
      • previous

        default LocalDate previous​(LocalDate date)
        Finds the previous business day, always returning an earlier date.

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

        Parameters:
        date - the date to adjust
        Returns:
        the first business day before the input date
        Throws:
        IllegalArgumentException - if the calculation is outside the supported range
      • previousOrSame

        default LocalDate previousOrSame​(LocalDate date)
        Finds the previous business day, returning the input date if it is a business day.

        Given a date, this method returns a business day. If the input date is a business day, it is returned. Otherwise, the previous business day is returned.

        Parameters:
        date - the date to adjust
        Returns:
        the input date if it is a business day, or the previous business day
        Throws:
        IllegalArgumentException - if the calculation is outside the supported range
      • nextSameOrLastInMonth

        default LocalDate nextSameOrLastInMonth​(LocalDate date)
        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.

        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
        Throws:
        IllegalArgumentException - if the calculation is outside the supported range
      • isLastBusinessDayOfMonth

        default boolean isLastBusinessDayOfMonth​(LocalDate date)
        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.

        Parameters:
        date - the date to check
        Returns:
        true if the specified date is the last business day of the month
        Throws:
        IllegalArgumentException - if the date is outside the supported range
      • lastBusinessDayOfMonth

        default LocalDate lastBusinessDayOfMonth​(LocalDate date)
        Calculates the last business day of the month.

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

        Parameters:
        date - the date to check
        Returns:
        the date of the last business day of the month
        Throws:
        IllegalArgumentException - if the date is outside the supported range
      • daysBetween

        default int daysBetween​(LocalDate startInclusive,
                                LocalDate endExclusive)
        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.

        Parameters:
        startInclusive - the start date
        endExclusive - the end date
        Returns:
        the total number of business days between the start and end date
        Throws:
        IllegalArgumentException - if either date is outside the supported range
      • businessDays

        default Stream<LocalDate> businessDays​(LocalDate startInclusive,
                                               LocalDate endExclusive)
        Gets the stream of business days between the two dates.

        This method will treat weekends as holidays. If the dates are equal, an empty stream is returned. If the end is before the start, an exception is thrown.

        Parameters:
        startInclusive - the start date
        endExclusive - the end date
        Returns:
        the stream of business days
        Throws:
        IllegalArgumentException - if either date is outside the supported range
      • holidays

        default Stream<LocalDate> holidays​(LocalDate startInclusive,
                                           LocalDate endExclusive)
        Gets the stream of holidays between the two dates.

        This method will treat weekends as holidays. If the dates are equal, an empty stream is returned. If the end is before the start, an exception is thrown.

        Parameters:
        startInclusive - the start date
        endExclusive - the end date
        Returns:
        the stream of holidays
        Throws:
        IllegalArgumentException - if either date is outside the supported range
      • combinedWith

        default HolidayCalendar combinedWith​(HolidayCalendar other)
        Combines this holiday calendar with another.

        The resulting calendar will declare a day as a business day if it is a business day in both source calendars.

        Parameters:
        other - the other holiday calendar
        Returns:
        the combined calendar
        Throws:
        IllegalArgumentException - if unable to combine the calendars
      • linkedWith

        default HolidayCalendar linkedWith​(HolidayCalendar other)
        Combines this holiday calendar with another.

        The resulting calendar will declare a day as a business day if it is a business day in either source calendar.

        Parameters:
        other - the other holiday calendar
        Returns:
        the combined calendar
      • getId

        HolidayCalendarId getId()
        Gets the identifier for the calendar.

        This identifier is used to locate the index in ReferenceData.

        Returns:
        the identifier
      • getName

        default String getName()
        Gets the name that identifies this calendar.

        This is the name associated with the identifier.

        Specified by:
        getName in interface Named
        Returns:
        the name