Class HolidayCalendar
java.lang.Object
cloud.opencode.base.date.holiday.HolidayCalendar
A calendar for managing and querying holidays
管理和查询假日的日历
This class provides a comprehensive holiday calendar with support for multiple years, holiday types, and workday calculations.
此类提供全面的假日日历,支持多年份、假日类型和工作日计算。
Features | 主要功能:
- Holiday storage and retrieval - 假日存储和检索
- Special workday (makeup day) support - 特殊工作日(调休日)支持
- Workday calculations - 工作日计算
- Year and month filtering - 年份和月份过滤
Usage Examples | 使用示例:
HolidayCalendar calendar = HolidayCalendar.builder()
.addHoliday(Holiday.of(LocalDate.of(2024, 1, 1), "New Year"))
.addHoliday(Holiday.of(LocalDate.of(2024, 12, 25), "Christmas"))
.addSpecialWorkday(LocalDate.of(2024, 9, 29)) // Makeup day
.build();
boolean isHoliday = calendar.isHoliday(LocalDate.of(2024, 1, 1)); // true
boolean isWorkday = calendar.isWorkday(LocalDate.of(2024, 1, 1)); // false
Security | 安全性:
- Thread-safe: Yes (immutable after construction via builder) - 线程安全: 是(通过构建器构造后不可变)
- 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 HolidayCalendar HolidayCalendar构建器 -
Method Summary
Modifier and TypeMethodDescriptionaddWorkdays(LocalDate date, int days) Adds workdays to a date 向日期添加工作日Creates a predicate for checking holidays 创建检查假日的谓词Creates a predicate for checking workdays 创建检查工作日的谓词static HolidayCalendar.Builderbuilder()Creates a builder 创建构建器longcountWorkdays(LocalDate start, LocalDate end) Counts workdays between two dates 计算两个日期之间的工作日数static HolidayCalendarempty()Creates an empty calendar 创建空日历findHoliday(LocalDate date) Gets the holiday for a date as Optional 获取日期的假日(Optional形式)Gets all holidays 获取所有假日getHoliday(LocalDate date) Gets the holiday for a date 获取日期的假日getHolidays(int year) Gets holidays for a specific year 获取特定年份的假日getHolidays(int year, Month month) Gets holidays for a specific year and month 获取特定年份和月份的假日Gets holidays of a specific type 获取特定类型的假日getHolidaysInRange(LocalDate start, LocalDate end) Gets holidays in a date range 获取日期范围内的假日getName()Gets the calendar name 获取日历名称Gets all special workdays 获取所有特殊工作日Gets the weekend days 获取周末天数booleanChecks if a date is a holiday 检查日期是否为假日booleanisPublicHoliday(LocalDate date) Checks if a date is a public holiday 检查日期是否为公共假日booleanisSpecialWorkday(LocalDate date) Checks if a date is a special workday 检查日期是否为特殊工作日booleanChecks if a date is a weekend 检查日期是否为周末booleanChecks if a date is a workday 检查日期是否为工作日nextWorkday(LocalDate date) Gets the next workday after the specified date 获取指定日期之后的下一个工作日static HolidayCalendarof(Collection<Holiday> holidays) Creates a calendar from a collection of holidays 从假日集合创建日历previousWorkday(LocalDate date) Gets the previous workday before the specified date 获取指定日期之前的上一个工作日toString()
-
Method Details
-
empty
Creates an empty calendar 创建空日历- Returns:
- the empty calendar | 空日历
-
of
Creates a calendar from a collection of holidays 从假日集合创建日历- Parameters:
holidays- the holidays | 假日集合- Returns:
- the calendar | 日历
-
builder
-
isHoliday
Checks if a date is a holiday 检查日期是否为假日- Parameters:
date- the date to check | 要检查的日期- Returns:
- true if it's a holiday | 如果是假日返回true
-
isPublicHoliday
Checks if a date is a public holiday 检查日期是否为公共假日- Parameters:
date- the date to check | 要检查的日期- Returns:
- true if it's a public 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
-
isWeekend
Checks if a date is a weekend 检查日期是否为周末- Parameters:
date- the date to check | 要检查的日期- Returns:
- true if it's a weekend | 如果是周末返回true
-
isWorkday
Checks if a date is a workday 检查日期是否为工作日- Parameters:
date- the date to check | 要检查的日期- Returns:
- true if it's a workday | 如果是工作日返回true
-
getHoliday
-
findHoliday
-
getAllHolidays
-
getHolidays
-
getHolidays
-
getHolidaysByType
Gets holidays of a specific type 获取特定类型的假日- Parameters:
type- the holiday type | 假日类型- Returns:
- the list of holidays | 假日列表
-
getHolidaysInRange
-
nextWorkday
-
previousWorkday
-
addWorkdays
-
countWorkdays
-
getName
-
getSpecialWorkdays
-
getWeekendDays
-
asHolidayPredicate
-
asWorkdayPredicate
-
toString
-