Class BusinessDayAdjuster

java.lang.Object
cloud.opencode.base.date.adjuster.BusinessDayAdjuster
All Implemented Interfaces:
TemporalAdjuster

public final class BusinessDayAdjuster extends Object implements TemporalAdjuster
Advanced business day adjuster with holiday and special workday support 高级工作日调整器,支持假日和特殊工作日

This class extends WorkdayAdjuster functionality with support for special workdays (e.g., Saturday makeup days in China) and complex holiday calendars.

此类扩展了WorkdayAdjuster的功能,支持特殊工作日 (如中国的周六调休日)和复杂的假日日历。

Features | 主要功能:

  • Standard workday calculations - 标准工作日计算
  • Holiday support - 假日支持
  • Special workday support (makeup days) - 特殊工作日支持(调休日)
  • Configurable business week - 可配置的工作周

Usage Examples | 使用示例:

// Chinese calendar with makeup workdays
Set<LocalDate> holidays = Set.of(
    LocalDate.of(2024, 10, 1),  // National Day
    LocalDate.of(2024, 10, 2),
    LocalDate.of(2024, 10, 3)
);
Set<LocalDate> makeupDays = Set.of(
    LocalDate.of(2024, 9, 29)   // Saturday makeup day
);

BusinessDayAdjuster adjuster = BusinessDayAdjuster.builder()
    .holidays(holidays)
    .specialWorkdays(makeupDays)
    .build();

// The makeup day (Saturday) will be counted as a workday
boolean isWorkday = adjuster.isBusinessDay(LocalDate.of(2024, 9, 29));
// true

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
  • Null-safe: Yes (with explicit null checks) - 空值安全: 是(有明确的空值检查)
Since:
JDK 25, opencode-base-date V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • plusDays

      public static BusinessDayAdjuster plusDays(int days)
      Creates an adjuster that adds the specified number of business days 创建添加指定工作日数的调整器
      Parameters:
      days - the number of business days to add | 要添加的工作日数
      Returns:
      the adjuster | 调整器
    • minusDays

      public static BusinessDayAdjuster minusDays(int days)
      Creates an adjuster that subtracts the specified number of business days 创建减去指定工作日数的调整器
      Parameters:
      days - the number of business days to subtract | 要减去的工作日数
      Returns:
      the adjuster | 调整器
    • nextBusinessDay

      public static BusinessDayAdjuster nextBusinessDay()
      Creates an adjuster that finds the next business day 创建查找下一个工作日的调整器
      Returns:
      the adjuster | 调整器
    • previousBusinessDay

      public static BusinessDayAdjuster previousBusinessDay()
      Creates an adjuster that finds the previous business day 创建查找上一个工作日的调整器
      Returns:
      the adjuster | 调整器
    • builder

      public static BusinessDayAdjuster.Builder builder()
      Creates a builder for customized business day adjusters 创建自定义工作日调整器的构建器
      Returns:
      the builder | 构建器
    • adjustInto

      public Temporal adjustInto(Temporal temporal)
      Specified by:
      adjustInto in interface TemporalAdjuster
    • isBusinessDay

      public boolean isBusinessDay(LocalDate date)
      Checks if a date is a business day 检查日期是否为工作日
      Parameters:
      date - the date to check | 要检查的日期
      Returns:
      true if it's a business day | 如果是工作日返回true
    • isHoliday

      public boolean isHoliday(LocalDate date)
      Checks if a date is a holiday 检查日期是否为假日
      Parameters:
      date - the date to check | 要检查的日期
      Returns:
      true if it's a holiday | 如果是假日返回true
    • isSpecialWorkday

      public boolean isSpecialWorkday(LocalDate date)
      Checks if a date is a special workday 检查日期是否为特殊工作日
      Parameters:
      date - the date to check | 要检查的日期
      Returns:
      true if it's a special workday | 如果是特殊工作日返回true
    • countBusinessDays

      public long countBusinessDays(LocalDate start, LocalDate end)
      Counts business days between two dates (exclusive of end date) 计算两个日期之间的工作日(不包括结束日期)
      Parameters:
      start - the start date | 开始日期
      end - the end date | 结束日期
      Returns:
      the number of business days | 工作日数
    • nextFrom

      public LocalDate nextFrom(LocalDate date)
      Finds the next business day from a given date 从给定日期查找下一个工作日
      Parameters:
      date - the starting date | 开始日期
      Returns:
      the next business day | 下一个工作日
    • previousFrom

      public LocalDate previousFrom(LocalDate date)
      Finds the previous business day from a given date 从给定日期查找上一个工作日
      Parameters:
      date - the starting date | 开始日期
      Returns:
      the previous business day | 上一个工作日
    • nthBusinessDayOfMonth

      public LocalDate nthBusinessDayOfMonth(int year, int month, int n)
      Finds the nth business day of the month 查找月份的第N个工作日
      Parameters:
      year - the year | 年份
      month - the month | 月份
      n - the ordinal (1-based) | 序数(从1开始)
      Returns:
      the nth business day | 第N个工作日
      Throws:
      IllegalArgumentException - if n is out of range | 如果n超出范围则抛出异常