Files
yunzerwebsiteallinone/go/pkg/holiday/fallback.go
T
2026-09-24 15:14:30 +08:00

123 lines
3.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package holiday
// fallbackData 内置的 2024-2026 年中国法定节假日/调休数据,
// 数据严格来自国务院办公厅历年《关于部分节假日安排的通知》原文。
//
// 用途:当外网接口不可达(内网部署、机房无外网出口、接口临时故障)且数据库
// 中也没有对应年份数据时,用本表兜底,保证日历控件always能显示休/班标记。
//
// 维护约定:每年 11 月国务院办公厅发布次年通知后,按下述格式补齐新一年数据
// (只补休假日与调休上班日两类,普通周末由前端按星期判定,不入表):
//
// notices = append(notices, yearNotice{Year: 2027, ...})
//
// 注意:这里只存"放假"与"补班"两类特殊日期;普通周六日不记录。
var fallbackData = buildFallback()
// yearNotice 单一年度的放假安排,按通知原文逐条录入。
type yearNotice struct {
Year int
// Holidays 放假日期区间:[开始日, 结束日],闭区间。
// 结束日与开始日相同表示只放一天;空串表示结束日等于开始日。
Holidays []dayRange
// Workdays 调休上班日(周末补班)。
Workdays []string
}
type dayRange struct {
Start string
End string
Name string
}
// yearNotices 各界各类节日的原始安排。
//
// 数据来源:
// - 2024:国办发明电〔2023〕7号
// - 2025:国办发明电〔2024〕12号
// - 2026:2025年11月4日国办通知
var yearNotices = []yearNotice{
{
Year: 2024,
Holidays: []dayRange{
{Start: "2024-01-01", Name: "元旦"},
{Start: "2024-02-10", End: "2024-02-17", Name: "春节"},
{Start: "2024-04-04", End: "2024-04-06", Name: "清明节"},
{Start: "2024-05-01", End: "2024-05-05", Name: "劳动节"},
{Start: "2024-06-10", Name: "端午节"},
{Start: "2024-09-15", End: "2024-09-17", Name: "中秋节"},
{Start: "2024-10-01", End: "2024-10-07", Name: "国庆节"},
},
Workdays: []string{
"2024-02-04", "2024-02-18",
"2024-04-07",
"2024-04-28", "2024-05-11",
"2024-09-14",
"2024-09-29", "2024-10-12",
},
},
{
Year: 2025,
Holidays: []dayRange{
{Start: "2025-01-01", Name: "元旦"},
{Start: "2025-01-28", End: "2025-02-04", Name: "春节"},
{Start: "2025-04-04", End: "2025-04-06", Name: "清明节"},
{Start: "2025-05-01", End: "2025-05-05", Name: "劳动节"},
{Start: "2025-05-31", End: "2025-06-02", Name: "端午节"},
{Start: "2025-10-01", End: "2025-10-08", Name: "国庆节、中秋节"},
},
Workdays: []string{
"2025-01-26", "2025-02-08",
"2025-04-27",
"2025-09-28", "2025-10-11",
},
},
{
Year: 2026,
Holidays: []dayRange{
{Start: "2026-01-01", End: "2026-01-03", Name: "元旦"},
{Start: "2026-02-15", End: "2026-02-23", Name: "春节"},
{Start: "2026-04-04", End: "2026-04-06", Name: "清明节"},
{Start: "2026-05-01", End: "2026-05-05", Name: "劳动节"},
{Start: "2026-06-19", End: "2026-06-21", Name: "端午节"},
{Start: "2026-09-25", End: "2026-09-27", Name: "中秋节"},
{Start: "2026-10-01", End: "2026-10-07", Name: "国庆节"},
},
Workdays: []string{
"2026-01-04",
"2026-02-14", "2026-02-28",
"2026-05-09",
"2026-09-20", "2026-10-10",
},
},
}
// buildFallback 把 yearNotices 展开成按日期索引的 Day 列表。
func buildFallback() []Day {
out := make([]Day, 0, 256)
for _, n := range yearNotices {
for _, r := range n.Holidays {
for _, d := range expandRange(r.Start, r.End) {
out = append(out, Day{
Date: d,
Name: r.Name,
Type: TypeHoliday,
Year: n.Year,
Source: SourceBuiltin,
})
}
}
for _, d := range n.Workdays {
out = append(out, Day{
Date: d,
Name: "调休上班",
Type: TypeWorkday,
Year: n.Year,
Wage: 1,
Source: SourceBuiltin,
})
}
}
return out
}