Class ChinaHolidayCalendar
- All Implemented Interfaces:
HolidayProvider
Input model:
输入模型:
- Holiday closed-interval ranges (放假闭区间), e.g. May Day, National Day, Qingming, Mid-Autumn. 一个或多个放假闭区间,例如:五一、十一、清明、中秋。
- Makeup-workday closed-interval ranges (补班闭区间), where weekends become workdays to compensate the holiday. 一个或多个补班闭区间,将周末调班为工作日。
Resolution rules (in order):
判定规则(按顺序):
- Date ∈ any makeup-workday range → workday (overrides weekend). 日期落入补班区间 → 工作日(覆盖周末)。
- Date ∈ any holiday range → holiday, not a workday. 日期落入放假区间 → 假日,非工作日。
- Otherwise → normal: weekend = non-workday, weekday = workday. 否则按正常处理:周末为非工作日,工作日为工作日。
Usage Examples | 使用示例:
// 2026 Labor Day: 5/1-5/5 holiday, 5/9 (Sat) makeup workday
ChinaHolidayCalendar cal = ChinaHolidayCalendar.builder()
.addEvent(ChinaHolidayEvent.builder()
.name("Labor Day").chineseName("劳动节")
.addHolidayRange(LocalDate.of(2026, 5, 1), LocalDate.of(2026, 5, 5))
.addMakeupWorkdayRange(LocalDate.of(2026, 5, 9), LocalDate.of(2026, 5, 9))
.build())
.build();
cal.isHoliday(LocalDate.of(2026, 5, 1)); // true
cal.isWorkday(LocalDate.of(2026, 5, 1)); // false
cal.isMakeupWorkday(LocalDate.of(2026, 5, 9)); // true
cal.isWorkday(LocalDate.of(2026, 5, 9)); // true (Saturday but makeup)
cal.isWorkday(LocalDate.of(2026, 6, 10)); // true (irrelevant date — normal weekday)
cal.isWorkday(LocalDate.of(2026, 6, 13)); // false (irrelevant date — normal Saturday)
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
- Null-safe: Yes (with explicit null checks) - 空值安全: 是(有明确的空值检查)
- Since:
- JDK 25, opencode-base-date V1.0.4
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder forChinaHolidayCalendar.static enumSelectable column forChinaHolidayCalendar.CalendarRowoutput.static final recordOne row of a calendar listing.static final recordPer-day classification under State-Council holiday rules.static enumKind of a calendar day under State-Council holiday rules. -
Method Summary
Modifier and TypeMethodDescriptionstatic ChinaHolidayCalendar.Builderbuilder()Creates a builder.Classifies a single date into aChinaHolidayCalendar.DayInfovia algorithm + configured data.intcountRestDaysInMonth(int year, int month) Counts rest days in the given month.intcountRestDaysInMonth(YearMonth yearMonth) Counts rest days in the given month.intcountRestDaysInYear(int year) Counts rest days in the given year.intcountWorkdaysInMonth(int year, int month) Counts workdays in the given month.intcountWorkdaysInMonth(YearMonth yearMonth) Counts workdays in the given month.intcountWorkdaysInYear(int year) Counts workdays in the given year.getAdjustedWorkdays(int year) Gets all configured makeup workdays for a specific year.Gets all configured makeup workdays.getCalendar(LocalDate start, LocalDate end) Generates a per-day calendar for a closed-interval date range.Gets the country/region code 获取国家/地区代码Returns the configured events.getHoliday(LocalDate date) Gets the holiday for a date, if any.getHolidays(int year) Gets all holidays for a specific year.getHolidays(LocalDate start, LocalDate end) Gets holidays in a closed-interval date range.getMonthCalendar(int year, int month) Generates a per-day calendar for an entire month.getMonthCalendar(YearMonth yearMonth) Generates a per-day calendar for an entire month.getMonthRestDayDates(int year, int month) Lists all rest day dates in the given month (in date order).getMonthRestDayDates(YearMonth yearMonth) Lists all rest day dates in the given month (in date order).getMonthRows(int year, int month) Outputs a month calendar listing with all four columns.getMonthRows(int year, int month, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs a month calendar listing with caller-selected columns.getMonthRows(YearMonth yearMonth) Outputs a month calendar listing with all four columns.getMonthRows(YearMonth yearMonth, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs a month calendar listing with caller-selected columns.getMonthWorkdayDates(int year, int month) Lists all workday dates in the given month (in date order).getMonthWorkdayDates(YearMonth yearMonth) Lists all workday dates in the given month (in date order).getName()Gets the provider name 获取提供者名称Outputs a calendar listing for a closed-interval date range with all four columns.getRows(LocalDate start, LocalDate end, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs a calendar listing for a closed-interval date range, with caller-selected columns.int[]Gets the supported year range, computed from the configured events.getWeekRows(LocalDate dateInWeek) Outputs the ISO week (Monday through Sunday) containing the given date, with all four columns.getWeekRows(LocalDate dateInWeek, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs the ISO week (Monday through Sunday) containing the given date, with caller-selected columns.getYearCalendar(int year) Generates a full-year per-day calendar (Jan 1 ..getYearRestDayDates(int year) Lists all rest day dates in the given year (in date order).getYearRestDays(int year) Returns a map of every rest day in the given year to its classification.getYearRows(int year) Outputs a full-year calendar listing with all four columns.getYearRows(int year, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs a full-year calendar listing with caller-selected columns.getYearWorkdayDates(int year) Lists all workday dates in the given year (in date order).getYearWorkdays(int year) Returns a map of every workday in the given year to its classification.booleanisAdjustedWorkday(LocalDate date) Alias forisMakeupWorkday(LocalDate)matching theHolidayProvidercontract.booleanReturns true if the date falls in any configured holiday range.booleanisMakeupWorkday(LocalDate date) Returns true if the date is a configured makeup workday (补班日).booleanReturns true if the date is Saturday or Sunday.booleanReturns true if the date is a workday under State-Council holiday rules.static ChinaHolidayCalendarof(Collection<ChinaHolidayEvent> events) Creates a calendar from a collection of events.Converts this calendar into a genericHolidayCalendar(without country binding).toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface HolidayProvider
isYearSupported, refresh
-
Method Details
-
builder
Creates a builder. 创建构建器。- Returns:
- a new builder | 新构建器
-
of
Creates a calendar from a collection of events. 通过事件集合创建日历。- Parameters:
events- the events | 事件集合- Returns:
- the calendar | 日历
-
getEvents
Returns the configured events. 返回配置的所有事件。- Returns:
- immutable list of events | 不可变事件列表
-
classify
Classifies a single date into aChinaHolidayCalendar.DayInfovia algorithm + configured data. 通过算法 + 已配置数据将单个日期分类为ChinaHolidayCalendar.DayInfo。Resolution order: makeup-workday range → holiday range → weekend default.
判定顺序:补班区间 → 放假区间 → 周末默认。
- Parameters:
date- the date | 日期- Returns:
- the classification | 分类信息
-
getYearCalendar
Generates a full-year per-day calendar (Jan 1 .. Dec 31, inclusive). 生成整年的逐日日历(1月1日 至 12月31日,闭区间)。- Parameters:
year- the year | 年份- Returns:
- ordered list of
ChinaHolidayCalendar.DayInfo| 按日期排序的ChinaHolidayCalendar.DayInfo列表
-
getCalendar
Generates a per-day calendar for a closed-interval date range. 生成闭区间日期范围内的逐日日历。- Parameters:
start- start date (inclusive) | 起始日期(包含)end- end date (inclusive) | 结束日期(包含)- Returns:
- ordered list of
ChinaHolidayCalendar.DayInfo| 按日期排序的ChinaHolidayCalendar.DayInfo列表
-
getYearWorkdays
Returns a map of every workday in the given year to its classification. 返回指定年份所有工作日及其分类信息的映射。- Parameters:
year- the year | 年份- Returns:
- ordered map of workdays | 按日期排序的工作日映射
-
getYearRestDays
Returns a map of every rest day in the given year to its classification. 返回指定年份所有休息日及其分类信息的映射。- Parameters:
year- the year | 年份- Returns:
- ordered map of rest days | 按日期排序的休息日映射
-
getMonthCalendar
Generates a per-day calendar for an entire month. 生成整月的逐日日历。- Parameters:
yearMonth- the year-month | 年月- Returns:
- ordered list of
ChinaHolidayCalendar.DayInfo| 按日期排序的ChinaHolidayCalendar.DayInfo列表
-
getMonthCalendar
Generates a per-day calendar for an entire month. 生成整月的逐日日历。- Parameters:
year- the year | 年份month- the month (1-12) | 月份(1-12)- Returns:
- ordered list of
ChinaHolidayCalendar.DayInfo| 按日期排序的ChinaHolidayCalendar.DayInfo列表
-
getYearWorkdayDates
-
getYearRestDayDates
-
getMonthWorkdayDates
-
getMonthWorkdayDates
-
getMonthRestDayDates
-
getMonthRestDayDates
-
countWorkdaysInYear
public int countWorkdaysInYear(int year) Counts workdays in the given year. 统计指定年份的工作日天数。- Parameters:
year- the year | 年份- Returns:
- workday count | 工作日天数
-
countRestDaysInYear
public int countRestDaysInYear(int year) Counts rest days in the given year. 统计指定年份的休息日天数。- Parameters:
year- the year | 年份- Returns:
- rest day count | 休息日天数
-
countWorkdaysInMonth
Counts workdays in the given month. 统计指定月份的工作日天数。- Parameters:
yearMonth- the year-month | 年月- Returns:
- workday count | 工作日天数
-
countWorkdaysInMonth
public int countWorkdaysInMonth(int year, int month) Counts workdays in the given month. 统计指定月份的工作日天数。- Parameters:
year- the year | 年份month- the month (1-12) | 月份(1-12)- Returns:
- workday count | 工作日天数
-
countRestDaysInMonth
Counts rest days in the given month. 统计指定月份的休息日天数。- Parameters:
yearMonth- the year-month | 年月- Returns:
- rest day count | 休息日天数
-
countRestDaysInMonth
public int countRestDaysInMonth(int year, int month) Counts rest days in the given month. 统计指定月份的休息日天数。- Parameters:
year- the year | 年份month- the month (1-12) | 月份(1-12)- Returns:
- rest day count | 休息日天数
-
getRows
Outputs a calendar listing for a closed-interval date range with all four columns. 输出闭区间日期范围内的日历清单(包含全部 4 列)。- Parameters:
start- start date (inclusive) | 起始日期(包含)end- end date (inclusive) | 结束日期(包含)- Returns:
- list of rows, one per day | 每日一行的清单
-
getRows
public List<ChinaHolidayCalendar.CalendarRow> getRows(LocalDate start, LocalDate end, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs a calendar listing for a closed-interval date range, with caller-selected columns. 输出闭区间日期范围内的日历清单,由调用方选择需要返回的列。Unselected columns are returned as
null. Passingnullor an empty field set returns all columns.未选中的列以
null返回。传入null或空集合等同于全部列。- Parameters:
start- start date (inclusive) | 起始日期(包含)end- end date (inclusive) | 结束日期(包含)fields- columns to populate | 要填充的列- Returns:
- immutable list of rows | 不可变清单
-
getYearRows
Outputs a full-year calendar listing with all four columns. 输出整年日历清单(包含全部 4 列)。- Parameters:
year- the year | 年份- Returns:
- list of rows | 清单
-
getYearRows
public List<ChinaHolidayCalendar.CalendarRow> getYearRows(int year, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs a full-year calendar listing with caller-selected columns. 输出整年日历清单,由调用方选择列。- Parameters:
year- the year | 年份fields- columns to populate | 要填充的列- Returns:
- immutable list of rows | 不可变清单
-
getMonthRows
Outputs a month calendar listing with all four columns. 输出整月日历清单(包含全部 4 列)。- Parameters:
yearMonth- the year-month | 年月- Returns:
- list of rows | 清单
-
getMonthRows
public List<ChinaHolidayCalendar.CalendarRow> getMonthRows(YearMonth yearMonth, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs a month calendar listing with caller-selected columns. 输出整月日历清单,由调用方选择列。- Parameters:
yearMonth- the year-month | 年月fields- columns to populate | 要填充的列- Returns:
- immutable list of rows | 不可变清单
-
getMonthRows
Outputs a month calendar listing with all four columns. 输出整月日历清单(包含全部 4 列)。- Parameters:
year- the year | 年份month- the month (1-12) | 月份(1-12)- Returns:
- list of rows | 清单
-
getMonthRows
public List<ChinaHolidayCalendar.CalendarRow> getMonthRows(int year, int month, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs a month calendar listing with caller-selected columns. 输出整月日历清单,由调用方选择列。- Parameters:
year- the year | 年份month- the month (1-12) | 月份(1-12)fields- columns to populate | 要填充的列- Returns:
- immutable list of rows | 不可变清单
-
getWeekRows
Outputs the ISO week (Monday through Sunday) containing the given date, with all four columns. 输出包含指定日期的 ISO 周(周一至周日)日历清单,包含全部 4 列。- Parameters:
dateInWeek- any date within the target week | 目标周内的任一日期- Returns:
- list of 7 rows in date order | 7 行(按日期排序)
-
getWeekRows
public List<ChinaHolidayCalendar.CalendarRow> getWeekRows(LocalDate dateInWeek, Set<ChinaHolidayCalendar.CalendarField> fields) Outputs the ISO week (Monday through Sunday) containing the given date, with caller-selected columns. 输出包含指定日期的 ISO 周(周一至周日)日历清单,由调用方选择列。- Parameters:
dateInWeek- any date within the target week | 目标周内的任一日期fields- columns to populate | 要填充的列- Returns:
- immutable list of 7 rows in date order | 不可变 7 行清单(按日期排序)
-
isHoliday
Returns true if the date falls in any configured holiday range. 如果日期落在任一已配置的放假区间内,返回 true。- Specified by:
isHolidayin interfaceHolidayProvider- Parameters:
date- the date | 日期- Returns:
- true if it's a holiday | 如果是节假日返回 true
-
isMakeupWorkday
Returns true if the date is a configured makeup workday (补班日). 如果日期为已配置的调休补班日,返回 true。- Parameters:
date- the date | 日期- Returns:
- true if makeup workday | 如果是补班日返回 true
-
isAdjustedWorkday
Alias forisMakeupWorkday(LocalDate)matching theHolidayProvidercontract. 与HolidayProvider接口对齐的别名方法。- Specified by:
isAdjustedWorkdayin interfaceHolidayProvider- Parameters:
date- the date | 日期- Returns:
- true if adjusted workday | 如果是调休工作日返回 true
-
isWeekend
Returns true if the date is Saturday or Sunday. Null-safe (returnsfalse). 当日期为星期六或星期日时返回 true。Null 安全(返回false)。- Parameters:
date- the date (nullable) | 日期(可为 null)- Returns:
- true if weekend | 如果是周末返回 true
-
isWorkday
Returns true if the date is a workday under State-Council holiday rules. Null-safe (returnsfalse). 在国务院假期规则下判断日期是否为工作日。Null 安全(返回false)。Resolution order: makeup-workday range > holiday range > weekend default.
判定顺序:补班区间 > 放假区间 > 周末默认。
- Specified by:
isWorkdayin interfaceHolidayProvider- Parameters:
date- the date (nullable) | 日期(可为 null)- Returns:
- true if workday | 如果是工作日返回 true
-
getHoliday
Gets the holiday for a date, if any. 获取该日期对应的节假日(若存在)。- Specified by:
getHolidayin interfaceHolidayProvider- Parameters:
date- the date | 日期- Returns:
- optional holiday | 可选节假日
-
getHolidays
Gets all holidays for a specific year. 获取指定年份的所有节假日。- Specified by:
getHolidaysin interfaceHolidayProvider- Parameters:
year- the year | 年份- Returns:
- list of holidays in date order | 按日期排序的节假日列表
-
getHolidays
Gets holidays in a closed-interval date range. 获取闭区间日期范围内的节假日。- Specified by:
getHolidaysin interfaceHolidayProvider- Parameters:
start- start date (inclusive) | 起始日期(包含)end- end date (inclusive) | 结束日期(包含)- Returns:
- list of holidays in date order | 按日期排序的节假日列表
-
getAdjustedWorkdays
Gets all configured makeup workdays for a specific year. 获取指定年份的所有补班日。- Specified by:
getAdjustedWorkdaysin interfaceHolidayProvider- Parameters:
year- the year | 年份- Returns:
- immutable set of makeup workdays | 不可变补班日集合
-
getAllMakeupWorkdays
-
getName
Description copied from interface:HolidayProviderGets the provider name 获取提供者名称- Specified by:
getNamein interfaceHolidayProvider- Returns:
- the provider name | 提供者名称
-
getCountryCode
Description copied from interface:HolidayProviderGets the country/region code 获取国家/地区代码- Specified by:
getCountryCodein interfaceHolidayProvider- Returns:
- the country code (e.g., "CN", "US") | 国家代码(如"CN"、"US")
-
getSupportedYearRange
public int[] getSupportedYearRange()Gets the supported year range, computed from the configured events. 获取受支持的年份范围(基于已配置事件计算)。If no events are configured, falls back to
[1970, 2100]: 1970 = Unix epoch (lower historical bound) and 2100 matches the upper bound used by sibling lunar/holiday data tables in this project. The fallback exists soHolidayProvider.isYearSupported(int)keeps a sensible default on an empty calendar; once any event is added, the range is the actual min/max of holiday + makeup-workday years.无配置事件时回退至
[1970, 2100]:1970 为 Unix 纪元下界,2100 与本项目阴历/节假日 数据表上界一致;该回退保证空日历下HolidayProvider.isYearSupported(int)仍有合理默认值。一旦添加事件, 实际范围即为放假/补班年份的最小/最大值。- Specified by:
getSupportedYearRangein interfaceHolidayProvider- Returns:
- [minYear, maxYear] inclusive | 含端点的 [minYear, maxYear]
-
toHolidayCalendar
Converts this calendar into a genericHolidayCalendar(without country binding). 将此日历转换为通用HolidayCalendar(不绑定国家代码)。- Returns:
- the generic holiday calendar | 通用节假日日历
-
toString
-