Install
openclaw skills install workday-calculator计算时间区间内有多少个工作日的技能。支持排除中国的节假日和调休安排。当用户询问工作日计算、节假日排除、工作时间计算时使用此技能。
openclaw skills install workday-calculator用于计算任意两个日期之间工作日数量的Python技能。支持排除中国的法定节假日和调休安排。
无需额外依赖,只需要Python 3.6+。
# 计算2025-01-01到2025-01-31之间的工作日
python3 scripts/workday_calculator.py 2025-01-01 2025-01-31
# 查看详细信息
python3 scripts/workday_calculator.py 2025-01-01 2025-01-31 --details
# 导出结果到JSON文件
python3 scripts/workday_calculator.py 2025-01-01 2025-01-31 --details --export result.json
参数:
start_date 开始日期 (格式: YYYY-MM-DD)
end_date 结束日期 (格式: YYYY-MM-DD)
选项:
--details 显示详细信息(工作日、节假日、周末列表)
--export 导出结果到JSON文件
workday-calculator/
├── SKILL.md # 本文件
├── scripts/
│ ├── workday_calculator.py # 主程序
│ ├── update_holidays.py # 节假日更新工具
│ └── example_usage.py # 使用示例
└── references/
└── holidays_2025_2026.md # 节假日数据文档
技能内置了2025-2026年的中国节假日数据,包括:
节假日数据需要每年更新,可以通过以下方式:
scripts/workday_calculator.py 文件中的 _load_holidays() 方法python3 scripts/update_holidays.py节假日数据基于以下来源:
$ python3 scripts/workday_calculator.py 2025-01-01 2025-01-31
从 2025-01-01 到 2025-01-31:
总天数: 31
工作日数量: 18
$ python3 scripts/workday_calculator.py 2026-02-01 2026-02-28 --details
=== 工作日计算详情 ===
时间区间: 2026-02-01 到 2026-02-28
总天数: 28
工作日数量: 17
节假日数量: 7
周末数量: 8
调休工作日数量: 2
工作日列表 (17天):
1. 2026-02-04 Tuesday
2. 2026-02-05 Wednesday
...
$ python3 scripts/example_usage.py
导出的JSON文件格式:
{
"start_date": "2025-01-01",
"end_date": "2025-01-31",
"workdays": ["2025-01-02", "2025-01-03", ...],
"holidays": ["2025-01-01"],
"weekends": ["2025-01-04", "2025-01-05", ...],
"extra_workdays": ["2025-02-08"],
"total_days": 31,
"workday_count": 22
}
from scripts.workday_calculator import WorkdayCalculator
calculator = WorkdayCalculator()
workdays = calculator.calculate_workdays(date(2025, 1, 1), date(2025, 1, 31))
print(f"工作日数量: {workdays}")
可以将脚本添加到系统PATH中:
# Linux/macOS
sudo ln -s $(pwd)/scripts/workday_calculator.py /usr/local/bin/workday-calc
# 使用
workday-calc 2025-01-01 2025-01-31
python3 scripts/update_holidays.py
scripts/workday_calculator.py 中的节假日数据可以扩展 update_holidays.py 来从政府网站API获取数据。
要支持其他国家的节假日,修改 WorkdayCalculator 类:
weekends 属性以匹配目标国家的周末定义holidays 和 extra_workdays 数据可以创建Flask或FastAPI应用,提供Web界面和REST API。
YYYY-MM-DD 格式日期格式错误:检查日期格式是否为 YYYY-MM-DD文件写入失败:检查导出目录的写入权限节假日数据缺失:更新节假日数据MIT License - 详见 LICENSE 文件
如有问题或建议,请通过GitHub Issues提交。