Class WorkdayAdjuster
java.lang.Object
cloud.opencode.base.date.adjuster.WorkdayAdjuster
- All Implemented Interfaces:
TemporalAdjuster
Temporal adjuster for workday calculations
工作日计算的时间调整器
This class provides adjusters for calculating workdays, taking into account weekends and optionally holidays.
此类提供计算工作日的调整器,考虑周末和可选的假日。
Features | 主要功能:
- Add/subtract workdays - 添加/减去工作日
- Find next/previous workday - 查找下一个/上一个工作日
- Configurable weekend days - 可配置的周末天数
- Custom holiday support - 自定义假日支持
Usage Examples | 使用示例:
LocalDate date = LocalDate.of(2024, 1, 5); // Friday
// Add 3 workdays
LocalDate after = date.with(WorkdayAdjuster.plusDays(3));
// 2024-01-10 (Wednesday, skips weekend)
// Next workday
LocalDate next = date.with(WorkdayAdjuster.nextWorkday());
// 2024-01-08 (Monday)
// With custom holidays
Set<LocalDate> holidays = Set.of(LocalDate.of(2024, 1, 8));
LocalDate after2 = date.with(WorkdayAdjuster.plusDays(1, holidays));
// 2024-01-09 (Tuesday, skips weekend and holiday)
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 WorkdayAdjuster WorkdayAdjuster构建器 -
Method Summary
Modifier and TypeMethodDescriptionadjustInto(Temporal temporal) static WorkdayAdjuster.Builderbuilder()Creates a builder for customized workday adjusters 创建自定义工作日调整器的构建器longcountWorkdays(LocalDate start, LocalDate end) Counts workdays between two dates (exclusive of end date) 计算两个日期之间的工作日(不包括结束日期)booleanChecks if a date is a workday 检查日期是否为工作日static WorkdayAdjusterminusDays(int days) Creates an adjuster that subtracts the specified number of workdays 创建减去指定工作日数的调整器static TemporalAdjusterCreates an adjuster that finds the nearest workday (or same if already a workday) 创建查找最近工作日的调整器(如果已是工作日则返回原日期)static WorkdayAdjusterCreates an adjuster that finds the next workday 创建查找下一个工作日的调整器static WorkdayAdjusternextWorkday(Set<LocalDate> holidays) Creates an adjuster that finds the next workday with custom holidays 创建查找下一个工作日并考虑自定义假日的调整器static WorkdayAdjusterplusDays(int days) Creates an adjuster that adds the specified number of workdays 创建添加指定工作日数的调整器static WorkdayAdjusterCreates an adjuster that adds workdays with custom holiday predicate 创建添加工作日并使用自定义假日谓词的调整器static WorkdayAdjusterCreates an adjuster that adds workdays with custom holidays 创建添加工作日并考虑自定义假日的调整器static WorkdayAdjusterCreates an adjuster that finds the previous workday 创建查找上一个工作日的调整器
-
Method Details
-
plusDays
Creates an adjuster that adds the specified number of workdays 创建添加指定工作日数的调整器- Parameters:
days- the number of workdays to add | 要添加的工作日数- Returns:
- the adjuster | 调整器
-
plusDays
Creates an adjuster that adds workdays with custom holidays 创建添加工作日并考虑自定义假日的调整器- Parameters:
days- the number of workdays to add | 要添加的工作日数holidays- the set of holidays | 假日集合- Returns:
- the adjuster | 调整器
-
plusDays
Creates an adjuster that adds workdays with custom holiday predicate 创建添加工作日并使用自定义假日谓词的调整器- Parameters:
days- the number of workdays to add | 要添加的工作日数holidayPredicate- predicate to check if a date is a holiday | 检查日期是否为假日的谓词- Returns:
- the adjuster | 调整器
-
minusDays
Creates an adjuster that subtracts the specified number of workdays 创建减去指定工作日数的调整器- Parameters:
days- the number of workdays to subtract | 要减去的工作日数- Returns:
- the adjuster | 调整器
-
nextWorkday
Creates an adjuster that finds the next workday 创建查找下一个工作日的调整器- Returns:
- the adjuster | 调整器
-
nextWorkday
Creates an adjuster that finds the next workday with custom holidays 创建查找下一个工作日并考虑自定义假日的调整器- Parameters:
holidays- the set of holidays | 假日集合- Returns:
- the adjuster | 调整器
-
previousWorkday
Creates an adjuster that finds the previous workday 创建查找上一个工作日的调整器- Returns:
- the adjuster | 调整器
-
nearestWorkday
Creates an adjuster that finds the nearest workday (or same if already a workday) 创建查找最近工作日的调整器(如果已是工作日则返回原日期)- Returns:
- the adjuster | 调整器
-
builder
Creates a builder for customized workday adjusters 创建自定义工作日调整器的构建器- Returns:
- the builder | 构建器
-
adjustInto
- Specified by:
adjustIntoin interfaceTemporalAdjuster
-
isWorkday
Checks if a date is a workday 检查日期是否为工作日- Parameters:
date- the date to check | 要检查的日期- Returns:
- true if it's a workday | 如果是工作日返回true
-
countWorkdays
-