Package Exports
- workday-cn
- workday-cn/lib/workday-cn.cjs.js
- workday-cn/lib/workday-cn.esm.js
- workday-cn/lib/workday-cn.umd.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (workday-cn) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
workday-cn
一个用于判断中国工作日的 JavaScript 工具包,支持法定节假日和调休判断。
特性
- 📅 支持 2018 年至今的节假日数据
- 🏢 支持法定节假日判断
- 🔄 支持调休工作日判断
- 📊 支持工作日范围计算
- 💾 支持离线使用 (静态数据)
- ⚡ 零配置,开箱即用
- 📦 支持多种模块规范 (CommonJS/ESM/UMD)
安装
npm install workday-cn
# 或
yarn add workday-cn
使用
支持多种模块引入方式:
// ESM
import { isWorkday } from 'workday-cn';
// CommonJS
const { isWorkday } = require('workday-cn');
// UMD (通过 CDN)
<script src="https://unpkg.com/workday-cn/lib/workday-cn.umd.js"></script>
const { isWorkday } = window.workdayCn;
API
日期判断
isWorkday(date: Date | string): boolean
判断指定日期是否为工作日(包含调休)。
isWorkday(new Date('2024-05-01')); // false
isWorkday('2024-05-02'); // false
isHoliday(date: Date | string): boolean
判断指定日期是否为法定节假日。
isHoliday(new Date('2024-05-01')); // true
isWeekend(date: Date | string): boolean
判断指定日期是否为周末。
isWeekend(new Date('2024-05-04')); // true
日期计算
getNextWorkday(date: Date | string): Date
获取指定日期之后的第一个工作日。
const next = getNextWorkday(new Date('2024-05-01'));
console.log(next); // 2024-05-06
getWorkdaysBetween(startDate: Date | string, endDate: Date | string): Date[]
获取两个日期之间的所有工作日。
const workdays = getWorkdaysBetween(
'2024-05-01',
'2024-05-10'
);
console.log(workdays.length); // 5
getWorkdays(date: Date | string, type: 'week' | 'month' = 'week'): Date[]
获取指定日期所在周或月的所有工作日。
// 获取本周工作日
const weekWorkdays = getWorkdays(new Date());
// 获取本月工作日
const monthWorkdays = getWorkdays(new Date(), 'month');
getMonthWorkdays(year: number, month: number): number
获取指定月份的工作日数量。
const count = getMonthWorkdays(2024, 5); // 获取2024年5月的工作日数量
getDateType(date: Date | string): string
获取指定日期的类型('workday' | 'holiday' | 'weekend')。
const type = getDateType(new Date('2024-05-01')); // 'holiday'
注意事项
- 日期参数支持 Date 对象或 'YYYY-MM-DD' 格式的字符串
- 节假日数据基于国务院发布的法定节假日安排《全国年节及纪念日放假办法》
- 每年的节假日数据会定期更新
许可
Copyright (c) 2025-present HonXin