Class BusinessDayAdjuster

  • All Implemented Interfaces:
    TemporalAdjuster

    public class BusinessDayAdjuster
    extends Object
    implements TemporalAdjuster
    A TemporalAdjuster that adds or subtracts a specified number of business days to a date.

    A business day is a date that is not a weekend or in the list of holidays.

    For example:

    LocalDate now = LocalDate.now(); LocalDate nextBusinessDay = now.with(BusinessDateAdjuster.addWorkDays(1));

    You can also use it with a Calendar object via the static helper methods.

    Calendar now = Calendar.getInstance(); Calendar nextBusinessDay = BusinessDateAdjuster.adjustCalendar(now, 1);

    • Constructor Detail

      • BusinessDayAdjuster

        public BusinessDayAdjuster​(int days)
        Creates a new BusinessDayAdjuster with no holidays and the default set of weekend days.
        Parameters:
        days - The number of business days to add (positive) or subtract (negative)
      • BusinessDayAdjuster

        public BusinessDayAdjuster​(int days,
                                   Set<LocalDate> holidays)
        Creates a new BusinessDayAdjuster with the given list of holidays and the default set of weekend days.
        Parameters:
        days - The number of business days to add (positive) or subtract (negative)
        holidays - A set of dates to be considered holidays (non-work days)
      • BusinessDayAdjuster

        public BusinessDayAdjuster​(int days,
                                   Set<LocalDate> holidays,
                                   Set<DayOfWeek> weekendDays)
        Creates a new BusinessDayAdjuster.
        Parameters:
        days - The number of business days to add (positive) or subtract (negative)
        holidays - A set of dates to be considered holidays (non-work days)
        weekendDays - A set of days to be considered weekends
    • Method Detail

      • addWorkDays

        public static BusinessDayAdjuster addWorkDays​(int days,
                                                      Set<LocalDate> holidays,
                                                      Set<DayOfWeek> weekendDays)
        Creates a BusinessDayAdjuster that adds the specified number of work days.
        Parameters:
        days - The number of work days to add
        holidays - A set of dates to be considered holidays
        weekendDays - A set of days to be considered weekends
        Returns:
        A BusinessDayAdjuster for use with LocalDate.with(TemporalAdjuster)
      • adjustCalendar

        public static Calendar adjustCalendar​(Calendar input,
                                              int days)
        Adjusts the specified calendar by the required number of business days.

        The input calendar is not modified.

        Parameters:
        input - The input calendar
        days - The number of business days to add (positive) or subtract (negative)
        Returns:
        The adjusted calendar, a separate object from the original
      • adjustCalendar

        public static Calendar adjustCalendar​(Calendar input,
                                              int days,
                                              Set<LocalDate> holidays)
        Adjusts the specified calendar by the required number of business days.

        The input calendar is not modified.

        Parameters:
        input - The input calendar
        days - The number of business days to add (positive) or subtract (negative)
        holidays - A set of dates to be considered holidays
        Returns:
        The adjusted calendar, a separate object from the original
      • adjustCalendar

        public static Calendar adjustCalendar​(Calendar input,
                                              int days,
                                              Set<LocalDate> holidays,
                                              Set<DayOfWeek> weekendDays)
        Adjusts the specified calendar by the required number of business days.

        The input calendar is not modified.

        Parameters:
        input - The input calendar
        days - The number of business days to add (positive) or subtract (negative)
        holidays - A set of dates to be considered holidays
        weekendDays - A set of days to be considered weekends
        Returns:
        The adjusted calendar, a separate object from the original