Interface Calendar

  • All Known Implementing Classes:
    CompositeCalendar, ConfigurableCalendar, FinancialCalendars

    public interface Calendar
    A calendar that handles date calculations, taking bank Holidays into account. Days that are not bank holidays are called business days.

    Subclasses of this interface are expected to be thread-safe and immutable.

    Since:
    2.1.0
    Author:
    Marc Wrobel
    • Field Detail

      • MAX_ITERATIONS

        static final int MAX_ITERATIONS
        Maximum number of iteration for date calculations before giving up.
        See Also:
        Constant Field Values
    • Method Detail

      • isHoliday

        boolean isHoliday​(LocalDate date)
        Check whether the given date is a public holiday.
        Parameters:
        date - a non-null date.
        Returns:
        true if the given date is a holiday, false otherwise.
      • getHolidaysFor

        Set<Holiday> getHolidaysFor​(LocalDate date)
        Get all the Holidays matching with the given day.
        Parameters:
        date - a non-null and unmodifiable set of Holidays.
        Returns:
        true if the given date is a holiday, false otherwise.
      • isBusinessDay

        default boolean isBusinessDay​(LocalDate date)
        Check whether the given date is a business day.
        Parameters:
        date - a non-null date.
        Returns:
        true if the given date is a business day, false otherwise.
      • shift

        default LocalDate shift​(LocalDate date,
                                int numberOfDays)
        Shifts the given date by the specified number of business days. If the given amount is
        • zero, the input date is returned,
        • positive, later business days are chosen
        • negative, earlier business days are chosen
        Parameters:
        date - the date to shift
        numberOfDays - the number of business days to adjust by
        Returns:
        a non-null date
        Throws:
        DateCalculationException - if no business day could be found in a reasonable time
      • previous

        default LocalDate previous​(LocalDate date)
        Compute the previous business day before the given date (excluded).
        Parameters:
        date - a non-null date
        Returns:
        a non-null date
        Throws:
        DateCalculationException - if no business day could be found in a reasonable time
      • previousOrSame

        default LocalDate previousOrSame​(LocalDate date)
        Compute the previous business day before the given date (included).
        Parameters:
        date - a non-null date
        Returns:
        a non-null date
        Throws:
        DateCalculationException - if no business day could be found in a reasonable time
      • next

        default LocalDate next​(LocalDate date)
        Compute the next business day after the given date (excluded).
        Parameters:
        date - a non-null date
        Returns:
        a non-null date
        Throws:
        DateCalculationException - if no business day could be found in a reasonable time
      • nextOrSame

        default LocalDate nextOrSame​(LocalDate date)
        Compute the next business day after the given date (included).
        Parameters:
        date - a non-null date
        Returns:
        a non-null date
        Throws:
        DateCalculationException - if no business day could be found in a reasonable time
      • holidaysWithin

        default List<LocalDate> holidaysWithin​(LocalDate from,
                                               LocalDate to)
        Compute the holidays between from (inclusive) and to (inclusive).
        Parameters:
        from - a non-null date
        to - a non-null date
        Returns:
        a non-null and unmodifiable ordered list of dates
        Throws:
        IllegalArgumentException - if from is after to
      • businessDaysWithin

        default List<LocalDate> businessDaysWithin​(LocalDate from,
                                                   LocalDate to)
        Compute the business days between from (inclusive) and to (inclusive).
        Parameters:
        from - a non-null date
        to - a non-null date
        Returns:
        a non-null and unmodifiable ordered list of dates
        Throws:
        IllegalArgumentException - if from is after to