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 Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default java.time.temporal.TemporalAdjuster adjustBy​(int amount)
      Returns an adjuster that changes the date.
      default java.util.stream.Stream<java.time.LocalDate> businessDays​(java.time.LocalDate startInclusive, java.time.LocalDate endExclusive)
      Gets the stream of business days between the two dates.
      default HolidayCalendar combinedWith​(HolidayCalendar other)
      Combines this holiday calendar with another.
      default int daysBetween​(java.time.LocalDate startInclusive, java.time.LocalDate endExclusive)
      Calculates the number of business days between two dates.
      HolidayCalendarId getId()
      Gets the identifier for the calendar.
      default java.lang.String getName()
      Gets the name that identifies this calendar.
      default java.util.stream.Stream<java.time.LocalDate> holidays​(java.time.LocalDate startInclusive, java.time.LocalDate endExclusive)
      Gets the stream of holidays between the two dates.
      default boolean isBusinessDay​(java.time.LocalDate date)
      Checks if the specified date is a business day.
      boolean isHoliday​(java.time.LocalDate date)
      Checks if the specified date is a holiday.
      default boolean isLastBusinessDayOfMonth​(java.time.LocalDate date)
      Checks if the specified date is the last business day of the month.
      default java.time.LocalDate lastBusinessDayOfMonth​(java.time.LocalDate date)
      Calculates the last business day of the month.
      default java.time.LocalDate next​(java.time.LocalDate date)
      Finds the next business day, always returning a later date.
      default java.time.LocalDate nextOrSame​(java.time.LocalDate date)
      Finds the next business day, returning the input date if it is a business day.
      default java.time.LocalDate nextSameOrLastInMonth​(java.time.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.
      default java.time.LocalDate previous​(java.time.LocalDate date)
      Finds the previous business day, always returning an earlier date.
      default java.time.LocalDate previousOrSame​(java.time.LocalDate date)
      Finds the previous business day, returning the input date if it is a business day.
      default java.time.LocalDate shift​(java.time.LocalDate date, int amount)
      Shifts the date by the specified number of business days.
    • Method Detail

      • isHoliday

        boolean isHoliday​(java.time.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:
        java.lang.IllegalArgumentException - if the date is outside the supported range
      • isBusinessDay

        default boolean isBusinessDay​(java.time.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:
        java.lang.IllegalArgumentException - if the date is outside the supported range
      • adjustBy

        default java.time.temporal.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:
        java.lang.IllegalArgumentException - if the calculation is outside the supported range
      • shift

        default java.time.LocalDate shift​(java.time.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:
        java.lang.IllegalArgumentException - if the calculation is outside the supported range
      • next

        default java.time.LocalDate next​(java.time.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:
        java.lang.IllegalArgumentException - if the calculation is outside the supported range
      • nextOrSame

        default java.time.LocalDate nextOrSame​(java.time.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:
        java.lang.IllegalArgumentException - if the calculation is outside the supported range
      • previous

        default java.time.LocalDate previous​(java.time.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:
        java.lang.IllegalArgumentException - if the calculation is outside the supported range
      • previousOrSame

        default java.time.LocalDate previousOrSame​(java.time.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:
        java.lang.IllegalArgumentException - if the calculation is outside the supported range
      • nextSameOrLastInMonth

        default java.time.LocalDate nextSameOrLastInMonth​(java.time.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:
        java.lang.IllegalArgumentException - if the calculation is outside the supported range
      • isLastBusinessDayOfMonth

        default boolean isLastBusinessDayOfMonth​(java.time.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:
        java.lang.IllegalArgumentException - if the date is outside the supported range
      • lastBusinessDayOfMonth

        default java.time.LocalDate lastBusinessDayOfMonth​(java.time.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:
        true if the specified date is the last business day of the month
        Throws:
        java.lang.IllegalArgumentException - if the date is outside the supported range
      • daysBetween

        default int daysBetween​(java.time.LocalDate startInclusive,
                                java.time.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:
        java.lang.IllegalArgumentException - if either date is outside the supported range
      • businessDays

        default java.util.stream.Stream<java.time.LocalDate> businessDays​(java.time.LocalDate startInclusive,
                                                                          java.time.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:
        java.lang.IllegalArgumentException - if either date is outside the supported range
      • holidays

        default java.util.stream.Stream<java.time.LocalDate> holidays​(java.time.LocalDate startInclusive,
                                                                      java.time.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:
        java.lang.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:
        java.lang.IllegalArgumentException - if unable to combine the calendars
      • getId

        HolidayCalendarId getId()
        Gets the identifier for the calendar.

        This identifier is used to locate the index in ReferenceData.

        Returns:
        the identifier
      • getName

        default java.lang.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