Class BusinessDayAdjuster
java.lang.Object
cloud.opencode.base.date.adjuster.BusinessDayAdjuster
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for BusinessDayAdjuster BusinessDayAdjuster构建器 -
Method Summary
Modifier and TypeMethodDescriptionadjustInto(Temporal temporal) static BusinessDayAdjuster.Builderbuilder()Creates a builder for customized business day adjusters 创建自定义工作日调整器的构建器longcountBusinessDays(LocalDate start, LocalDate end) Counts business days between two dates (exclusive of end date) 计算两个日期之间的工作日(不包括结束日期)booleanisBusinessDay(LocalDate date) Checks if a date is a business day 检查日期是否为工作日booleanChecks if a date is a holiday 检查日期是否为假日booleanisSpecialWorkday(LocalDate date) Checks if a date is a special workday 检查日期是否为特殊工作日static BusinessDayAdjusterminusDays(int days) Creates an adjuster that subtracts the specified number of business days 创建减去指定工作日数的调整器static BusinessDayAdjusterCreates an adjuster that finds the next business day 创建查找下一个工作日的调整器Finds the next business day from a given date 从给定日期查找下一个工作日nthBusinessDayOfMonth(int year, int month, int n) Finds the nth business day of the month 查找月份的第N个工作日static BusinessDayAdjusterplusDays(int days) Creates an adjuster that adds the specified number of business days 创建添加指定工作日数的调整器static BusinessDayAdjusterCreates an adjuster that finds the previous business day 创建查找上一个工作日的调整器previousFrom(LocalDate date) Finds the previous business day from a given date 从给定日期查找上一个工作日
-
Method Details
-
plusDays
Creates an adjuster that adds the specified number of business days 创建添加指定工作日数的调整器- Parameters:
days- the number of business days to add | 要添加的工作日数- Returns:
- the adjuster | 调整器
-
minusDays
Creates an adjuster that subtracts the specified number of business days 创建减去指定工作日数的调整器- Parameters:
days- the number of business days to subtract | 要减去的工作日数- Returns:
- the adjuster | 调整器
-
nextBusinessDay
Creates an adjuster that finds the next business day 创建查找下一个工作日的调整器- Returns:
- the adjuster | 调整器
-
previousBusinessDay
Creates an adjuster that finds the previous business day 创建查找上一个工作日的调整器- Returns:
- the adjuster | 调整器
-
builder
Creates a builder for customized business day adjusters 创建自定义工作日调整器的构建器- Returns:
- the builder | 构建器
-
adjustInto
- Specified by:
adjustIntoin interfaceTemporalAdjuster
-
isBusinessDay
Checks if a date is a business day 检查日期是否为工作日- Parameters:
date- the date to check | 要检查的日期- Returns:
- true if it's a business day | 如果是工作日返回true
-
isHoliday
Checks if a date is a holiday 检查日期是否为假日- Parameters:
date- the date to check | 要检查的日期- Returns:
- true if it's a holiday | 如果是假日返回true
-
isSpecialWorkday
Checks if a date is a special workday 检查日期是否为特殊工作日- Parameters:
date- the date to check | 要检查的日期- Returns:
- true if it's a special workday | 如果是特殊工作日返回true
-
countBusinessDays
-
nextFrom
-
previousFrom
-
nthBusinessDayOfMonth
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超出范围则抛出异常
-