|
@@ -0,0 +1,90 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+ <head>
|
|
|
+ <meta charset="UTF-8" />
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
|
+ <title>Test</title>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+ <script type="module">
|
|
|
+ import { isWorkday, isHoliday, isInLieu, getDayDetail, getHolidaysInRange, getWorkdaysInRange, findWorkday, getSolarTerms, getLunarDate } from 'https://cdn.jsdelivr.net/npm/chinese-days/dist/index.es.js'
|
|
|
+
|
|
|
+ console.log(isWorkday('2020-01-01'));
|
|
|
+ console.log(isHoliday('2020-01-01'));
|
|
|
+
|
|
|
+ // 检查 2024-05-02 返回 `true` 则表示是一个调休日。
|
|
|
+ console.log(isInLieu('2024-05-02')); // true
|
|
|
+
|
|
|
+ // 检查 2024-05-01 返回 `false` 则表示不是一个调休日。
|
|
|
+ console.log(isInLieu('2024-05-01')); // false
|
|
|
+
|
|
|
+ // 正常工作日 周五
|
|
|
+ console.log(getDayDetail('2024-02-02')); // { "date": "2024-02-02", "work":true,"name":"Friday"}
|
|
|
+ // 节假日 周末
|
|
|
+ console.log(getDayDetail('2024-02-03')); // { "date": "2024-02-03", "work":false,"name":"Saturday"}
|
|
|
+ // 调休需要上班
|
|
|
+ console.log(getDayDetail('2024-02-04')); // { "date": "2024-02-04", "work":true,"name":"Spring Festival,春节,3"}
|
|
|
+ // 节假日 春节
|
|
|
+ console.log(getDayDetail('2024-02-17')); // { "date": "2024-02-17", "work":false,"name":"Spring Festival,春节,3"}
|
|
|
+
|
|
|
+ const start = '2024-04-26';
|
|
|
+ const end = '2024-05-06';
|
|
|
+
|
|
|
+ // 获取从 2024-05-01 到 2024-05-10 的所有节假日,包括周末
|
|
|
+ const holidaysIncludingWeekends = getHolidaysInRange(start, end, true);
|
|
|
+ console.log('Holidays including weekends:', holidaysIncludingWeekends.map(d => getDayDetail(d)));
|
|
|
+
|
|
|
+ // 获取从 2024-05-01 到 2024-05-10 的节假日,不包括周末
|
|
|
+ const holidaysExcludingWeekends = getHolidaysInRange(start, end, false);
|
|
|
+ console.log('Holidays excluding weekends:', holidaysExcludingWeekends.map(d => getDayDetail(d)));
|
|
|
+
|
|
|
+
|
|
|
+ // 获取从 2024-05-01 到 2024-05-10 的所有工作日,包括周末
|
|
|
+ const workdaysIncludingWeekends = getWorkdaysInRange(start, end, true);
|
|
|
+ console.log('Workdays including weekends:', workdaysIncludingWeekends);
|
|
|
+
|
|
|
+ // 获取从 2024-05-01 到 2024-05-10 的工作日,不包括周末
|
|
|
+ const workdaysExcludingWeekends = getWorkdaysInRange(start, end, false);
|
|
|
+ console.log('Workdays excluding weekends:', workdaysExcludingWeekends);
|
|
|
+
|
|
|
+ const currentWorkday = findWorkday(0);
|
|
|
+ console.log(currentWorkday);
|
|
|
+
|
|
|
+ // 查找从今天开始未来的第一个工作日
|
|
|
+ const nextWorkday = findWorkday(1);
|
|
|
+ console.log(nextWorkday);
|
|
|
+
|
|
|
+ // 查找从今天开始之前的前一个工作日
|
|
|
+ const previousWorkday = findWorkday(-1);
|
|
|
+ console.log(previousWorkday);
|
|
|
+
|
|
|
+ // 可以传第二个参数 查找具体日期的上下工作日
|
|
|
+ // 查找从 2024-05-18 开始,未来的第二个工作日
|
|
|
+ const secondNextWorkday = findWorkday(2, '2024-05-18');
|
|
|
+ console.log(secondNextWorkday);
|
|
|
+
|
|
|
+
|
|
|
+ /** 获取范围内 节气日期数组 */
|
|
|
+ const solarTerms = getSolarTerms("2024-05-01", "2024-05-20");
|
|
|
+ solarTerms.forEach(({ date, term, name }) => {
|
|
|
+ console.log(`${name}: ${date}, ${term}`);
|
|
|
+ });
|
|
|
+ // 立夏: 2024-05-05, the_beginning_of_summer
|
|
|
+ // 小满: 2024-05-20, lesser_fullness_of_grain
|
|
|
+
|
|
|
+ // 没有节气 返回 []
|
|
|
+ console.log(getSolarTerms("2024-05-21", "2024-05-25"))
|
|
|
+ // return []
|
|
|
+
|
|
|
+ /* 不传 end 参数, 获取某天 节气 */
|
|
|
+ console.log(getSolarTerms("2024-05-20"));
|
|
|
+ // return: [{date: '2024-05-20', term: 'lesser_fullness_of_grain', name: '小满'}]
|
|
|
+
|
|
|
+ // 2097-8-7
|
|
|
+ console.log(getLunarDate('2097-08-07'))
|
|
|
+
|
|
|
+ // 2057-9-28
|
|
|
+ console.log(getLunarDate('2057-09-28'))
|
|
|
+ </script>
|
|
|
+ </body>
|
|
|
+</html>
|