Browse Source

Merge pull request #19 from vsme/dev

文档迁移至 vitepress
Yawei sun 8 months ago
parent
commit
f3b82cf628
54 changed files with 1002 additions and 2009 deletions
  1. 4 1
      .github/workflows/deploy-docs.yml
  2. 4 3
      .gitignore
  3. 7 267
      README.en.md
  4. 4 267
      README.md
  5. 0 30
      docs/.gitignore
  6. 25 0
      docs/.vitepress/config.ts
  7. 90 0
      docs/.vitepress/en.ts
  8. 24 0
      docs/.vitepress/theme/custom.css
  9. 4 0
      docs/.vitepress/theme/index.ts
  10. 114 0
      docs/.vitepress/zh.ts
  11. 0 7
      docs/.vscode/extensions.json
  12. 0 39
      docs/README.md
  13. 42 13
      docs/components/calendar-comp.vue
  14. 5 0
      docs/en/demo/calendar.md
  15. 0 0
      docs/en/guide/24-solar-terms.md
  16. 0 0
      docs/en/guide/contributing.md
  17. 0 0
      docs/en/guide/from-lunar.md
  18. 0 0
      docs/en/guide/getting-started.md
  19. 0 0
      docs/en/guide/holidays.md
  20. 0 0
      docs/en/guide/lieu-days.md
  21. 0 0
      docs/en/guide/thank.md
  22. 0 0
      docs/en/guide/to-lunar.md
  23. 0 0
      docs/en/guide/what-is-chinese-days.md
  24. 0 0
      docs/en/guide/working-days.md
  25. 24 0
      docs/en/index.md
  26. 0 4
      docs/env.d.ts
  27. 0 9
      docs/eslint.config.mjs
  28. 0 14
      docs/index.html
  29. 297 786
      docs/package-lock.json
  30. 11 25
      docs/package.json
  31. 0 90
      docs/public/demo-es.html
  32. BIN
      docs/public/favicon.ico
  33. 0 0
      docs/public/home.svg
  34. BIN
      docs/public/icon.png
  35. 0 47
      docs/src/App.vue
  36. 0 247
      docs/src/assets/main.css
  37. 0 89
      docs/src/components/DocsComp.vue
  38. 0 6
      docs/src/main.ts
  39. 0 14
      docs/tsconfig.app.json
  40. 0 11
      docs/tsconfig.json
  41. 0 19
      docs/tsconfig.node.json
  42. 0 21
      docs/vite.config.ts
  43. 5 0
      docs/zh/demo/calendar.md
  44. 58 0
      docs/zh/guide/24-solar-terms.md
  45. 7 0
      docs/zh/guide/contributing.md
  46. 11 0
      docs/zh/guide/from-lunar.md
  47. 59 0
      docs/zh/guide/getting-started.md
  48. 27 0
      docs/zh/guide/holidays.md
  49. 13 0
      docs/zh/guide/lieu-days.md
  50. 4 0
      docs/zh/guide/thank.md
  51. 39 0
      docs/zh/guide/to-lunar.md
  52. 31 0
      docs/zh/guide/what-is-chinese-days.md
  53. 70 0
      docs/zh/guide/working-days.md
  54. 23 0
      docs/zh/index.md

+ 4 - 1
.github/workflows/deploy-docs.yml

@@ -9,6 +9,9 @@ on:
     tags:
       - "v*"
 
+  # Allows you to run this workflow manually from the Actions tab on GitHub.
+  workflow_dispatch:
+
 # A workflow run is made up of one or more jobs that can run sequentially or in parallel
 jobs:
   # This workflow contains a single job called "build"
@@ -40,4 +43,4 @@ jobs:
         uses: peaceiris/actions-gh-pages@v4
         with:
           github_token: ${{ secrets.GITHUB_TOKEN }}
-          publish_dir: ./docs/dist
+          publish_dir: ./docs/.vitepress/dist

+ 4 - 3
.gitignore

@@ -1,5 +1,6 @@
-node_modules/
-dist/
-coverage/
+node_modules
+dist
+cache
+coverage
 
 .DS_Store

+ 7 - 267
README.en.md

@@ -4,7 +4,13 @@
 [![GitHub License](https://img.shields.io/github/license/vsme/chinese-days)](https://github.com/vsme/chinese-days/blob/main/LICENSE)
 [![README](https://img.shields.io/badge/README-中文-brightgreen.svg)](https://github.com/vsme/chinese-days/blob/main/README.md)
 
-This project provides a series of functions for querying Chinese holidays, adjusted working days, working days, 24 solar terms, and converting between lunar and solar calendars. Additionally, it supports ics file subscription for holidays, which can be subscribed to by Google Calendar, Apple Calendar, Microsoft Outlook, and other clients. The holiday information will be updated according to the announcements from the State Council.
+This project provides a series of functions for querying Chinese holidays, adjusted working days, working days, 24 solar terms, and converting between lunar and solar calendars. Additionally, it supports ics file subscription for holidays, which can be subscribed to by Google Calendar, Apple Calendar, Microsoft Outlook, and other clients. 
+
+## Documentation
+
+To check out docs, visit [chinese-days.yaavi.me](https://chinese-days.yaavi.me/en/).
+
+The holiday information will be updated according to the announcements from the State Council.
 
 + **Holidays**: Supports the years 2004 to 2025, including the extended Spring Festival of 2020.
 + **24 Solar Terms**: Supports the years 1900 to 2100.
@@ -24,272 +30,6 @@ A `JSON` file of Chinese holidays is provided and can be directly referenced thr
 
 For example, in `Java`, you can refer to [Warnier-zhang/java-chinese-days](https://github.com/Warnier-zhang/java-chinese-days), which is only for querying Chinese holidays, in-lieu days, and regular workdays.
 
-## Quick Start
-
-### Recommended approach
-
-Direct browser import for more timely updates
-
-```html
-<script src="https://cdn.jsdelivr.net/npm/chinese-days/dist/index.min.js"></script>
-<script>
-  chineseDays.isHoliday('2024-01-01');
-  // Or use destructuring
-  const { isHoliday } = chineseDays;
-</script>
-```
-
-OR
-
-```html
-<script type="module">
-  import chineseDays from 'https://cdn.jsdelivr.net/npm/chinese-days/dist/index.es.js'
-  chineseDays.isHoliday('2024-01-01');
-</script>
-```
-
-### Installation:
-
-```sh
-npm i chinese-days
-```
-
-Using ESM import:
-
-```ts
-import chineseDays from 'chinese-days';
-console.log(chineseDays);
-```
-
-Using in Node.js:
-
-```js
-const { isWorkday, isHoliday } = require('chinese-days');
-console.log(isWorkday('2020-01-01'));
-console.log(isHoliday('2020-01-01'));
-```
-
-## Holiday Module
-
-### `isWorkday` Check if a date is a workday
-
-```js
-console.log(isWorkday('2023-01-01')); // false
-```
-
-### `isHoliday` Check if a date is a holiday
-
-```js
-console.log(isHoliday('2023-01-01')); // true
-```
-
-### `isInLieu` Check if a date is an in lieu day
-
-On a Chinese holiday arrangement, an in lieu day is a workday or a rest day adjusted for consecutive holidays or make-up workdays. For example, if a public holiday is connected to a weekend, a weekend day might be adjusted to a workday, or a workday might be adjusted to a rest day for a longer consecutive holiday.
-
-```js
-// Check if 2024-05-02 is an in lieu day. Returns `true` if it is.
-console.log(isInLieu('2024-05-02')); // true
-
-// Check if 2024-05-01 is an in lieu day. Returns `false` if it is not.
-console.log(isInLieu('2024-05-01')); // false
-```
-
-### `getDayDetail` Check if a specified date is a workday
-
-This function checks if a specified date is a workday and returns a boolean indicating if it's a workday and details about the date.
-
-1. If the specified date is a workday, it returns true and the name of the workday. If it's a make-up workday, it returns true and holiday details.
-2. If it's a holiday, it returns false and holiday details.
-
-```js
-// Example usage
-
-// Regular workday, Friday
-console.log(getDayDetail('2024-02-02')); // { "date": "2024-02-02", "work":true,"name":"Friday"}
-// Holiday, Saturday
-console.log(getDayDetail('2024-02-03')); // { "date": "2024-02-03", "work":false,"name":"Saturday"}
-// Make-up workday
-console.log(getDayDetail('2024-02-04')); // { "date": "2024-02-04", "work":true,"name":"Spring Festival,春节,3"}
-// Holiday, Spring Festival
-console.log(getDayDetail('2024-02-17')); // { "date": "2024-02-17", "work":false,"name":"Spring Festival,春节,3"}
-```
-
-### `getHolidaysInRange` Get all holidays within a specified date range
-
-Receives start and end dates and optionally includes weekends. If weekends are included, the function returns all holidays including weekends; otherwise, only holidays on weekdays are returned.
-
-> Tip: Even if weekends are not included, holidays that fall on weekends will still be returned.
-
-```js
-// Example usage
-const start = '2024-04-26';
-const end = '2024-05-06';
-
-// Get all holidays from 2024-05-01 to 2024-05-10, including weekends
-const holidaysIncludingWeekends = getHolidaysInRange(start, end, true);
-console.log('Holidays including weekends:', holidaysIncludingWeekends.map(d => getDayDetail(d)));
-
-// Get holidays from 2024-05-01 to 2024-05-10, excluding weekends
-const holidaysExcludingWeekends = getHolidaysInRange(start, end, false);
-console.log('Holidays excluding weekends:', holidaysExcludingWeekends.map(d => getDayDetail(d)));
-```
-
-### `getWorkdaysInRange` Get a list of workdays within a specified date range
-
-Receives start and end dates and optionally includes weekends. If weekends are included, the function returns all workdays including weekends; otherwise, only weekdays (Monday to Friday) workdays are returned.
-
-```js
-// Example usage
-const start = '2024-04-26';
-const end = '2024-05-06';
-
-// Get all workdays from 2024-05-01 to 2024-05-10, including weekends
-const workdaysIncludingWeekends = getWorkdaysInRange(start, end, true);
-console.log('Workdays including weekends:', workdaysIncludingWeekends);
-
-// Get workdays from 2024-05-01 to 2024-05-10, excluding weekends
-const workdaysExcludingWeekends = getWorkdaysInRange(start, end, false);
-console.log('Workdays excluding weekends:', workdaysExcludingWeekends);
-```
-
-### `findWorkday` Find a workday
-
-Find the workday that is {deltaDays} workdays from today.
-
-```js
-// Find the workday that is {deltaDays} workdays from today
-// If deltaDays is 0, first check if today is a workday. If it is, return today.
-// If today is not a workday, find the next workday.
-const currentWorkday = findWorkday(0);
-console.log(currentWorkday);
-
-// Find the next workday from today
-const nextWorkday = findWorkday(1);
-console.log(nextWorkday);
-
-// Find the previous workday from today
-const previousWorkday = findWorkday(-1);
-console.log(previousWorkday);
-
-// You can pass a second parameter to find a specific date's workdays
-// Find the second workday from 2024-05-18
-const secondNextWorkday = findWorkday(2, '2024-05-18');
-console.log(secondNextWorkday);
-```
-
-## Solar Terms Module
-
-### Get Dates for the 24 Solar Terms
-
-The 24 solar terms in China are part of a traditional agricultural calendar, marking different **time periods** throughout the year. Each term typically has a specific start date, but this date does not represent the entire duration of the term. In fact, each solar term lasts about 15 days.
-
-For example, the term "Lesser Fullness of Grain" (小满) typically starts around May 20th in the Gregorian calendar, but it doesn't end on that day. Instead, it lasts until the next solar term begins. Specifically, "Lesser Fullness of Grain" lasts until around June 5th, when the "Grain in Ear" (芒种) term begins. Therefore, the time period for the "Lesser Fullness of Grain" solar term is from approximately May 20th to June 5th.
-
-#### Get an Array of Solar Terms Dates within a Range
-
-```js
-import { getSolarTermsInRange } from "chinese-days";
-
-// No parameters, queries the current day
-console.log(getSolarTermsInRange())
-// [{date: '2024-05-29', term: 'lesser_fullness_of_grain', name: '小满', index: 10}]
-// index: indicates the day within the current term, starting from 1
-
-// No end parameter, queries for a specific date
-console.log(getSolarTermsInRange('2024-05-01'))
-// [{date: '2024-05-01', term: 'grain_rain', name: '谷雨', index: 13}]
-
-// Query solar terms within a specified range
-console.log(getSolarTermsInRange('2024-05-01', '2024-05-06'))
-/**
- * =>
- * [
- *   {"date":"2024-05-01","term":"grain_rain","name":"谷雨","index":13},
- *   {"date":"2024-05-02","term":"grain_rain","name":"谷雨","index":14},
- *   {"date":"2024-05-03","term":"grain_rain","name":"谷雨","index":15},
- *   {"date":"2024-05-04","term":"grain_rain","name":"谷雨","index":16},
- *   {"date":"2024-05-05","term":"the_beginning_of_summer","name":"立夏","index":1},
- *   {"date":"2024-05-06","term":"the_beginning_of_summer","name":"立夏","index":2}
- * ]
- **/
-```
-
-#### If You Only Want to Get an Array of Solar Term Start Dates
-
-```js
-import { getSolarTerms } from "chinese-days";
-
-/** Get an array of solar term start dates within a range */
-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
-
-// No solar terms found, returns []
-getSolarTerms("2024-05-21", "2024-05-25");
-// return []
-
-/* No end parameter, get the solar term for a specific day */
-getSolarTerms("2024-05-20");
-// return: [{date: '2024-05-20', term: 'lesser_fullness_of_grain', name: '小满'}]
-```
-
-## Conversion Between Gregorian and Lunar Calendar
-
-Special notes for this library:
-1. `2057-09-28` is the lunar date: `丁丑` year, August 30th;
-2. `2097-08-07` is the lunar date: `丁巳` year, July 1st.
-
-### Convert Gregorian Date to Lunar Date
-
-```js
-// 2097-08-07
-console.log(getLunarDate('2097-08-07'));
-
-// 2057-09-28
-console.log(getLunarDate('2057-09-28'));
-// Output:
-// {
-//   date: "2057-09-28",
-//   lunarYear: 2057,
-//   lunarMon: 8,
-//   lunarDay: 30,
-//   isLeap: false,
-//   lunarDayCN: "三十",
-//   lunarMonCN: "八月",
-//   lunarYearCN: "二零五七",
-//   yearCyl: "丁丑",
-//   monCyl: "己酉",
-//   dayCyl: "戊子",
-//   zodiac: "牛"
-// }
-
-// Examples of non-leap and leap months
-console.log(getLunarDate('2001-04-27'));
-console.log(getLunarDate('2001-05-27'));
-```
-
-### Get Lunar Dates in a Range of Gregorian Dates
-
-```js
-console.log(getLunarDatesInRange('2001-05-21', '2001-05-26'));
-```
-
-### Convert Lunar Date to Gregorian Date
-
-When dealing with a leap month in the lunar calendar, one lunar date may correspond to two different Gregorian dates, hence the return is in object form.
-
-```js
-console.log(getSolarDateFromLunar('2001-03-05'));
-// Output: {date: '2001-03-29', leapMonthDate: undefined}
-
-console.log(getSolarDateFromLunar('2001-04-05'));
-// Output: {date: '2001-04-27', leapMonthDate: '2001-05-27'}
-```
-
 ## Contributing
 
 1. Fork + Clone the project to your local machine;

+ 4 - 267
README.md

@@ -6,6 +6,10 @@
 
 本项目提供了一系列用于查询中国节假日、调休日、工作日、24节气、以及农历阳历互转的函数,此外还支持 `iCal` 文件订阅节假日,可供 Google Calendar、Apple Calendar、Microsoft Outlook 等客户端订阅。
 
+## 文档
+
+查看文档, 请访问 [chinese-days.yaavi.me](https://chinese-days.yaavi.me/).
+
 每日会执行 `Action` 自动抓取数据,节假日变化时发送邮件提醒,信息会跟随国务院发布进行更新。
 
 + **节假日**:支持 2004年 至 2025年,包括 2020年 的春节延长
@@ -26,273 +30,6 @@ For English: [https://cdn.jsdelivr.net/npm/chinese-days/dist/holidays.en.ics](ht
 
 订阅的日历包含近三年(2023-2025年)的节假日和调休日。
 
-## 快速开始
-
-### 推荐方式
-
-直接浏览器引入,更新较为及时
-
-```html
-<script src="https://cdn.jsdelivr.net/npm/chinese-days/dist/index.min.js"></script>
-<script>
-  chineseDays.isHoliday('2024-01-01');
-  // 或者解构使用
-  const { isHoliday } = chineseDays;
-</script>
-```
-
-或者
-
-```html
-<script type="module">
-  import chineseDays from 'https://cdn.jsdelivr.net/npm/chinese-days/dist/index.es.js'
-  chineseDays.isHoliday('2024-01-01');
-</script>
-```
-
-### 其他方式安装
-
-```sh
-npm i chinese-days
-```
-
-使用 ESM 导入
-
-```ts
-import chineseDays from 'chinese-days';
-console.log(chineseDays);
-```
-
-在 Node 中使用
-
-```js
-const { isWorkday, isHoliday } = require('chinese-days');
-console.log(isWorkday('2020-01-01'));
-console.log(isHoliday('2020-01-01'));
-```
-
-## 节假日模块
-
-### `isWorkday` 检查某个日期是否为工作日
-
-```js
-console.log(isWorkday('2023-01-01')); // false
-```
-
-### `isHoliday` 检查某个日期是否为节假日
-
-```js
-console.log(isHoliday('2023-01-01')); // true
-```
-
-### `isInLieu` 检查某个日期是否为调休日(in lieu day)
-
-在中国的节假日安排中,调休日是为了连休假期或补班而调整的工作日或休息日。例如,当某个法定假日与周末相连时,可能会将某个周末调整为工作日,或者将某个工作日调整为休息日,以便连休更多天。
-
-```js
-// 检查 2024-05-02 返回 `true` 则表示是一个调休日。
-console.log(isInLieu('2024-05-02')); // true
-
-// 检查 2024-05-01 返回 `false` 则表示不是一个调休日。
-console.log(isInLieu('2024-05-01')); // false
-```
-
-
-### `getDayDetail` 检查指定日期是否是工作日
-
-函数用于检查指定日期是否是工作日,并返回一个是否工作日的布尔值和日期的详情。
-
-1. 如果指定日期是工作日,则返回 true 和工作日名称,如果是被调休的工作日,返回 true 和节假日详情。
-2. 如果是节假日,则返回 false 和节假日详情。
-
-```js
-// 示例用法
-
-// 正常工作日 周五
-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"}
-```
-
-### `getHolidaysInRange` 获取指定日期范围内的所有节假日
-
-接收起始日期和结束日期,并可选地决定是否包括周末。如果包括周末,则函数会返回包括周末在内的所有节假日;否则,只返回工作日的节假日。
-
-> tip: 即使不包括周末,周末的节假日仍然会被返回
-
-```js
-// 示例用法
-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)));
-```
-
-
-### `getWorkdaysInRange` 取指定日期范围内的工作日列表
-
-接收起始日期和结束日期,并可选地决定是否包括周末。如果包括周末,则函数会返回包括周末在内的所有工作日;否则,只返回周一到周五的工作日。
-
-```js
-// 示例用法
-const start = '2024-04-26';
-const end = '2024-05-06';
-
-// 获取从 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);
-```
-
-### `findWorkday` 查找工作日
-
-查找从今天开始 未来的第 {deltaDays} 个工作日。
-
-```js
-// 查找从今天开始 未来的第 {deltaDays} 个工作日
-// 如果 deltaDays 为 0,首先检查当前日期是否为工作日。如果是,则直接返回当前日期。
-// 如果当前日期不是工作日,会查找下一个工作日。
-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);
-```
-
-## 节气模块
-
-### 获取 24 节气的日期
-
-中国的二十四节气是传统的农业历法,它们标志着一年中不同的**时间段**。每个节气通常有特定的(开始)日期,但这个日期并不代表整个节气的持续时间。事实上,每个节气大约持续15天。
-
-以“小满”为例,它的日期通常在公历5月20日左右开始,但并不止于这一天,而是持续到下一个节气开始。具体来说,小满大约持续到6月5日(芒种)前后。因此,“小满”节气的时间段是从5月20日左右到6月5日左右。
-
-#### 获取范围内节气日期数组
-
-```js
-import { getSolarTermsInRange } from "chinese-days";
-
-// 不传,查询当天
-console.log(getSolarTermsInRange())
-// [{date: '2024-05-29', term: 'lesser_fullness_of_grain', name: '小满', index: 10}]
-// index: 代表处于当前节气的第几天,从 1 开始
-
-// 不传end,查询指定日期
-console.log(getSolarTermsInRange('2024-05-01'))
-// [{date: '2024-05-01', term: 'grain_rain', name: '谷雨', index: 13}]
-
-// 查询范围内的节气
-console.log(getSolarTermsInRange('2024-05-01', '2024-05-06'))
-/**
- * =>
- * [
- *   {"date":"2024-05-01","term":"grain_rain","name":"谷雨","index":13},
- *   {"date":"2024-05-02","term":"grain_rain","name":"谷雨","index":14},
- *   {"date":"2024-05-03","term":"grain_rain","name":"谷雨","index":15},
- *   {"date":"2024-05-04","term":"grain_rain","name":"谷雨","index":16},
- *   {"date":"2024-05-05","term":"the_beginning_of_summer","name":"立夏","index":1},
- *   {"date":"2024-05-06","term":"the_beginning_of_summer","name":"立夏","index":2}
- * ]
- **/
-```
-
-#### 如果你仅想获取节气**开始日期**数组
-
-```js
-import { getSolarTerms } from "chinese-days";
-
-/** 获取范围内 节气的开始日期数组 */
-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
-
-// 没有节气 返回 []
-getSolarTerms("2024-05-21", "2024-05-25");
-// return []
-
-/* 不传 end 参数, 获取某天 节气 */
-getSolarTerms("2024-05-20");
-// return: [{date: '2024-05-20', term: 'lesser_fullness_of_grain', name: '小满'}]
-```
-
-## 阳历农历互转
-
-特别说明,此库中:
-1. `2057-09-28` 为:农历丁丑(牛)年八月三十;
-2. `2097-08-07` 为:农历丁巳(蛇)年七月初一。
-
-### 阳历转换农历
-
-```js
-// 2097-8-7
-console.log(getLunarDate('2097-08-07'));
-
-// 2057-9-28
-console.log(getLunarDate('2057-09-28'));
-// {
-//   date: "2057-09-28",
-//   lunarYear: 2057,
-//   lunarMon: 8,
-//   lunarDay: 30,
-//   isLeap: false,
-//   lunarDayCN: "三十",
-//   lunarMonCN: "八月",
-//   lunarYearCN: "二零五七",
-//   yearCyl: "丁丑",
-//   monCyl: "己酉",
-//   dayCyl: "戊子",
-//   zodiac: "牛"
-// }
-
-// 非闰月 和 闰月例子
-console.log(getLunarDate('2001-04-27'));
-console.log(getLunarDate('2001-05-27'));
-```
-
-### 根据阳历日期区间,批量获取农历日期
-
-```js
-console.log(getLunarDatesInRange('2001-05-21', '2001-05-26'));
-```
-
-### 农历转换阳历
-
-当为阴历闰月的时候,会出现一个农历日期对应两个阳历日期的情况,所以返回对象形式。
-
-```js
-console.log(getSolarDateFromLunar('2001-03-05'));
-// {date: '2001-03-29', leapMonthDate: undefined}
-
-console.log(getSolarDateFromLunar('2001-04-05'));
-// {date: '2001-04-27', leapMonthDate: '2001-05-27'}
-```
-
 ## 贡献代码
 
 1. Fork + Clone 项目到本地;

+ 0 - 30
docs/.gitignore

@@ -1,30 +0,0 @@
-# Logs
-logs
-*.log
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-pnpm-debug.log*
-lerna-debug.log*
-
-node_modules
-.DS_Store
-dist
-dist-ssr
-coverage
-*.local
-
-/cypress/videos/
-/cypress/screenshots/
-
-# Editor directories and files
-.vscode/*
-!.vscode/extensions.json
-.idea
-*.suo
-*.ntvs*
-*.njsproj
-*.sln
-*.sw?
-
-*.tsbuildinfo

+ 25 - 0
docs/.vitepress/config.ts

@@ -0,0 +1,25 @@
+import { defineConfig } from 'vitepress'
+import { en } from './en'
+import { zh } from './zh'
+
+// https://vitepress.dev/reference/site-config
+export default defineConfig({
+  title: "Chinese Days",
+
+  head: [
+    ['link', { rel: 'icon', type: 'image/png', href: '/icon.png' }],
+  ],
+
+  rewrites: {
+    'zh/:rest*': ':rest*'
+  },
+
+  themeConfig: {
+    logo: { src: '/icon.png', width: 24, height: 24 },
+  },
+
+  locales: {
+    root: { label: '简体中文', ...zh },
+    en: { label: 'English', ...en },
+  },
+})

+ 90 - 0
docs/.vitepress/en.ts

@@ -0,0 +1,90 @@
+import { createRequire } from 'module'
+import { DefaultTheme, defineConfig } from 'vitepress'
+
+const require = createRequire(import.meta.url)
+const pkg = require('chinese-days/package.json')
+
+export const en = defineConfig({
+  description: "A VitePress Site",
+
+  themeConfig: {
+    // https://vitepress.dev/reference/default-theme-config
+    nav: [
+      { text: 'Guide', link: '/en/guide/what-is-chinese-days' },
+      { text: 'Demo', link: '/en/demo/calendar' },
+      {
+        text: pkg.version,
+        link: 'https://github.com/vsme/chinese-days/blob/main/CHANGELOG.md'
+      },
+    ],
+
+    sidebar: {
+      '/en/guide/': { base: '/en/guide/', items: sidebarGuide() },
+      '/en/demo/': { base: '/en/demo/', items: sidebarDemo() }
+    },
+
+    socialLinks: [
+      { icon: 'github', link: 'https://github.com/vsme/chinese-days' }
+    ],
+
+    footer: {
+      message: 'Released under the MIT License.',
+      copyright: 'Copyright © 2024-present Yawei Sun'
+    },
+  }
+})
+
+function sidebarGuide(): DefaultTheme.SidebarItem[] {
+  return [
+    {
+      text: 'Introduction',
+      collapsed: false,
+      items: [
+        { text: 'What is Chinese Days', link: 'what-is-chinese-days' },
+        { text: 'Getting started', link: 'getting-started' },
+      ]
+    },
+    {
+      text: 'Holidays',
+      collapsed: false,
+      items: [
+        { text: 'Holidays', link: 'holidays' },
+        { text: 'Lieu Days', link: 'lieu-days' },
+        { text: 'Working Days', link: 'working-days' },
+      ]
+    },
+    {
+      text: '24 Solar Terms',
+      collapsed: false,
+      items: [
+        { text: 'Apis', link: '24-solar-terms' },
+      ]
+    },
+    {
+      text: 'Lunar',
+      collapsed: false,
+      items: [
+        { text: 'Solar to Lunar', link: 'to-lunar' },
+        { text: 'Lunar to Solar', link: 'from-lunar' }
+      ]
+    },
+    { text: 'Else',
+      collapsed: false,
+      items: [
+        { text: 'Contributing', link: 'contributing' },
+        { text: 'Thank', link: 'thank' }
+      ]
+    }
+  ]
+}
+
+function sidebarDemo(): DefaultTheme.SidebarItem[] {
+  return [
+    {
+      text: 'Demo',
+      items: [
+        { text: 'Calendar', link: 'calendar' }
+      ]
+    }
+  ]
+}

+ 24 - 0
docs/.vitepress/theme/custom.css

@@ -0,0 +1,24 @@
+:root {
+  --vp-c-brand-1: #ffa8a8;
+  --vp-c-brand-2: #e75c5c;
+  --vp-c-brand-3: #dd3e3e;
+  --vp-c-brand-soft: rgba(255, 100, 100, 0.16);
+
+  --vp-home-hero-name-color: transparent;
+  --vp-home-hero-name-background: linear-gradient(120deg, #fe3480 30%, #ffd941);
+
+  --vp-home-hero-image-background-image: linear-gradient(-45deg, #fe3480 50%, #ffd941 50%);
+  --vp-home-hero-image-filter: blur(44px);
+}
+
+@media (min-width: 640px) {
+  :root {
+    --vp-home-hero-image-filter: blur(56px);
+  }
+}
+
+@media (min-width: 960px) {
+  :root {
+    --vp-home-hero-image-filter: blur(68px);
+  }
+}

+ 4 - 0
docs/.vitepress/theme/index.ts

@@ -0,0 +1,4 @@
+import DefaultTheme from 'vitepress/theme'
+import './custom.css'
+
+export default DefaultTheme

+ 114 - 0
docs/.vitepress/zh.ts

@@ -0,0 +1,114 @@
+import { createRequire } from 'module'
+import { DefaultTheme, defineConfig } from 'vitepress'
+
+const require = createRequire(import.meta.url)
+const pkg = require('chinese-days/package.json')
+
+export const zh = defineConfig({
+  description: "A VitePress Site",
+
+  themeConfig: {
+    // https://vitepress.dev/reference/default-theme-config
+    nav: [
+      { text: '指南', link: '/guide/what-is-chinese-days' },
+      { text: '示例', link: '/demo/calendar' },
+      {
+        text: pkg.version,
+        link: 'https://github.com/vsme/chinese-days/blob/main/CHANGELOG.md'
+      },
+    ],
+
+    sidebar: {
+      '/guide/': { base: '/guide/', items: sidebarGuide() },
+      '/demo/': { base: '/demo/', items: sidebarDemo() }
+    },
+
+    socialLinks: [
+      { icon: 'github', link: 'https://github.com/vsme/chinese-days' }
+    ],
+
+    footer: {
+      message: '基于 MIT 许可发布',
+      copyright: `Copyright © 2019-${new Date().getFullYear()} Yawei Sun`
+    },
+
+    docFooter: {
+      prev: '上一页',
+      next: '下一页'
+    },
+
+    outline: {
+      label: '页面导航'
+    },
+
+    lastUpdated: {
+      text: '最后更新于',
+      formatOptions: {
+        dateStyle: 'short',
+        timeStyle: 'medium'
+      }
+    },
+
+    langMenuLabel: '多语言',
+    returnToTopLabel: '回到顶部',
+    sidebarMenuLabel: '菜单',
+    darkModeSwitchLabel: '主题',
+    lightModeSwitchTitle: '切换到浅色模式',
+    darkModeSwitchTitle: '切换到深色模式'
+  }
+})
+
+function sidebarGuide(): DefaultTheme.SidebarItem[] {
+  return [
+    {
+      text: '简介',
+      collapsed: false,
+      items: [
+        { text: 'Chinese Days', link: 'what-is-chinese-days' },
+        { text: '快速开始', link: 'getting-started' },
+      ]
+    },
+    {
+      text: '节假日',
+      collapsed: false,
+      items: [
+        { text: '节假日', link: 'holidays' },
+        { text: '调休日', link: 'lieu-days' },
+        { text: '工作日', link: 'working-days' },
+      ]
+    },
+    {
+      text: '24节气',
+      collapsed: false,
+      items: [
+        { text: '使用方法', link: '24-solar-terms' },
+      ]
+    },
+    {
+      text: '阴历/农历',
+      collapsed: false,
+      items: [
+        { text: '阳历转农历', link: 'to-lunar' },
+        { text: '农历转阳历', link: 'from-lunar' }
+      ]
+    },
+    { text: '其他',
+      collapsed: false,
+      items: [
+        { text: '贡献指南', link: 'contributing' },
+        { text: '致谢', link: 'thank' }
+      ]
+    }
+  ]
+}
+
+function sidebarDemo(): DefaultTheme.SidebarItem[] {
+  return [
+    {
+      text: '使用示例',
+      items: [
+        { text: '日历', link: 'calendar' }
+      ]
+    }
+  ]
+}

+ 0 - 7
docs/.vscode/extensions.json

@@ -1,7 +0,0 @@
-{
-  "recommendations": [
-    "Vue.volar",
-    "dbaeumer.vscode-eslint",
-    "esbenp.prettier-vscode"
-  ]
-}

+ 0 - 39
docs/README.md

@@ -1,39 +0,0 @@
-# demo
-
-This template should help get you started developing with Vue 3 in Vite.
-
-## Recommended IDE Setup
-
-[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
-
-## Type Support for `.vue` Imports in TS
-
-TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
-
-## Customize configuration
-
-See [Vite Configuration Reference](https://vitejs.dev/config/).
-
-## Project Setup
-
-```sh
-npm install
-```
-
-### Compile and Hot-Reload for Development
-
-```sh
-npm run dev
-```
-
-### Type-Check, Compile and Minify for Production
-
-```sh
-npm run build
-```
-
-### Lint with [ESLint](https://eslint.org/)
-
-```sh
-npm run lint
-```

+ 42 - 13
docs/src/components/CalendarComp.vue → docs/components/calendar-comp.vue

@@ -1,5 +1,6 @@
 <script lang="ts" setup>
 import { computed, ref } from 'vue'
+import chineseDays from "chinese-days"
 
 const { getDayDetail, getLunarDate, getSolarTermsInRange, isInLieu } = chineseDays
 
@@ -9,7 +10,7 @@ const props = withDefaults(
     startOfWeek?: 1 | 2 | 3 | 4 | 5 | 6 | 0
   }>(),
   {
-    lang: 'en',
+    lang: 'zh',
     startOfWeek: 1,
   },
 )
@@ -146,7 +147,7 @@ const daysInfo = computed(() => daysInMonth.value.map((date: Date) => getDayInfo
         </svg>
       </button>
       <h2 v-if="lang === 'zh'">
-        <select v-model="currentYear">
+        <select v-model="currentYear" style="width: 130px;">
           <option v-for="(y, index) in 201" :key="index" :value="1900 + index">
             {{ 1900 + index }}
           </option>
@@ -159,8 +160,18 @@ const daysInfo = computed(() => daysInMonth.value.map((date: Date) => getDayInfo
         </select>
       </h2>
-      <h2 v-else>
-        {{ monthNames[currentMonth] }} {{ currentYear }}
+      <h2 v-else>        
+        <select v-model="currentMonth" style="width: 160px;">
+          <option v-for="(month, index) in 12" :key="index" :value="index">
+            {{ monthNames[month - 1] }}
+          </option>
+        </select>
+        
+        <select v-model="currentYear">
+          <option v-for="(y, index) in 201" :key="index" :value="1900 + index">
+            {{ 1900 + index }}
+          </option>
+        </select>
       </h2>
       <button @click="nextMonth">
         <svg
@@ -263,12 +274,28 @@ body {
   max-width: var(--calendar-max-width);
   margin: 0 auto;
   padding: var(--calendar-padding);
-  border: var(--calendar-border-width) solid #ddd;
+  border: var(--calendar-border-width) solid var(--vp-c-gray-2);
   border-radius: var(--calendar-border-radius);
   position: relative;
-  background: #fff;
+  background: var(--vp-c-bg);
   z-index: 1;
 
+  h2, p {
+    margin: 0;
+    padding: 0;
+    border: 0;
+  }
+
+  select {
+    font-size: 24px;
+    width: 100px;
+    margin: 0 15px;
+    font-weight: bold;
+    text-align: center;
+    border: 1px solid var(--vp-c-default-3);
+    border-radius: 6px;
+  }
+
   .calendar-header {
     display: flex;
     justify-content: space-between;
@@ -339,7 +366,7 @@ body {
       border-radius: var(--calendar-border-radius);
       position: relative;
       transition: all 0.2s ease;
-      color: #333;
+      color: var(--vp-c-text-1);
 
       &:nth-child(7n + 6),
       &:nth-child(7n + 7) {
@@ -395,8 +422,8 @@ body {
       }
 
       &:hover {
-        background: rgba(78, 110, 242, 0.1);
-        color: #333;
+        background: rgba(118, 142, 240, 0.2);
+        color: var(--vp-c-text-1);
       }
 
       &.solar {
@@ -447,8 +474,8 @@ body {
   max-width: var(--calendar-max-width);
   margin: 0 auto;
   padding: 50px 20px 30px;
-  background: #f2f2f2;
-  border: var(--calendar-border-width) solid #f2f2f2;
+  background: var(--vp-c-gray-3);
+  border: var(--calendar-border-width) solid var(--vp-c-gray-3);
   border-radius: var(--calendar-border-radius);
   position: relative;
   top: -20px;
@@ -465,6 +492,7 @@ body {
     p {
       font-weight: bold;
       font-size: 14px;
+      margin: 0;
       &:first-child {
         font-size: 22px;
       }
@@ -476,9 +504,10 @@ body {
     flex-flow: column nowrap;
     align-items: flex-start;
     padding-left: var(--calendar-padding);
-    border-left: 1px solid #ddd;
+    border-left: 1px solid var(--vp-c-gray-2);
     p {
       font-size: 14px;
+      margin: 0;
       span {
         font-weight: bold;
       }
@@ -500,4 +529,4 @@ body {
     }
   }
 }
-</style>
+</style>

+ 5 - 0
docs/en/demo/calendar.md

@@ -0,0 +1,5 @@
+<script setup>
+  import Calendar from '../../components/calendar-comp.vue'
+</script>
+
+<Calendar lang="en" />

+ 0 - 0
docs/en/guide/24-solar-terms.md


+ 0 - 0
docs/en/guide/contributing.md


+ 0 - 0
docs/en/guide/from-lunar.md


+ 0 - 0
docs/en/guide/getting-started.md


+ 0 - 0
docs/en/guide/holidays.md


+ 0 - 0
docs/en/guide/lieu-days.md


+ 0 - 0
docs/en/guide/thank.md


+ 0 - 0
docs/en/guide/to-lunar.md


+ 0 - 0
docs/en/guide/what-is-chinese-days.md


+ 0 - 0
docs/en/guide/working-days.md


File diff suppressed because it is too large
+ 24 - 0
docs/en/index.md


+ 0 - 4
docs/env.d.ts

@@ -1,4 +0,0 @@
-/// <reference types="vite/client" />
-
-// chineseDays
-declare var chineseDays: any;

+ 0 - 9
docs/eslint.config.mjs

@@ -1,9 +0,0 @@
-import antfu from '@antfu/eslint-config'
-
-export default antfu(
-  {
-    vue: true,
-    typescript: true,
-    ignores: ['*.js'],
-  },
-)

+ 0 - 14
docs/index.html

@@ -1,14 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <link rel="icon" href="/favicon.ico">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Chinese Days</title>
-    <script src="//cdn.jsdelivr.net/npm/chinese-days/dist/index.min.js"></script>
-  </head>
-  <body>
-    <div id="app"></div>
-    <script type="module" src="/src/main.ts"></script>
-  </body>
-</html>

File diff suppressed because it is too large
+ 297 - 786
docs/package-lock.json


+ 11 - 25
docs/package.json

@@ -1,34 +1,20 @@
 {
-  "name": "demo",
+  "name": "docs",
   "type": "module",
   "version": "0.0.0",
   "private": true,
   "scripts": {
-    "dev": "vite",
-    "build": "run-p type-check \"build-only {@}\" --",
-    "preview": "vite preview",
-    "build-only": "vite build",
-    "type-check": "vue-tsc --build --force",
-    "lint": "eslint .",
-    "lint:fix": "eslint . --fix"
-  },
-  "dependencies": {
-    "highlight.js": "^11.10.0",
-    "markdown-it": "^14.1.0",
-    "vue": "^3.4.38"
+    "dev": "vitepress dev",
+    "build": "vitepress build",
+    "preview": "vitepress preview"
   },
+  "author": "",
+  "license": "ISC",
+  "description": "",
   "devDependencies": {
-    "@antfu/eslint-config": "^2.27.1",
-    "@tsconfig/node20": "^20.1.4",
-    "@types/markdown-it": "^14.1.2",
-    "@types/node": "^22.5.0",
-    "@vitejs/plugin-vue": "^5.1.2",
-    "@vue/tsconfig": "^0.5.1",
-    "eslint": "^9.9.1",
-    "npm-run-all2": "^6.2.2",
-    "typescript": "~5.5.4",
-    "vite": "^5.4.2",
-    "vite-plugin-vue-devtools": "^7.3.9",
-    "vue-tsc": "^2.0.29"
+    "vitepress": "^1.5.0"
+  },
+  "dependencies": {
+    "chinese-days": "^1.4.0"
   }
 }

+ 0 - 90
docs/public/demo-es.html

@@ -1,90 +0,0 @@
-<!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>

BIN
docs/public/favicon.ico


File diff suppressed because it is too large
+ 0 - 0
docs/public/home.svg


BIN
docs/public/icon.png


+ 0 - 47
docs/src/App.vue

@@ -1,47 +0,0 @@
-<script lang="ts" setup>
-import { ref } from 'vue'
-import Calendar from './components/CalendarComp.vue'
-import Docs from './components/DocsComp.vue'
-
-const lang = ref<'zh' | 'en'>('zh')
-</script>
-
-<template>
-  <!-- <button @click="lang = lang === 'zh' ? 'en' : 'zh'">{{ lang === 'zh' ? 'en' : 'zh' }}</button> -->
-  <div class="demo-title">
-    <span>Chinese Days - Demo</span>
-    <a href="https://github.com/vsme/chinese-days" target="_blank" rel="noopener noreferrer">
-      <img src="//img.shields.io/github/stars/vsme/chinese-days" alt="GitHub Repo stars">
-    </a>
-  </div>
-  <Calendar :lang />
-  <Docs />
-</template>
-
-<style>
-#app {
-  text-align: center;
-  color: #2c3e50;
-  padding: 20px 0;
-  @media screen and (max-width: 560px) {
-    padding: 10px 0;
-  }
-  .demo-title {
-    max-width: 680px;
-    padding: 10px 20px 30px;
-    margin: 0 auto;
-    text-align: left;
-    font-size: 1.25em;
-    font-weight: bold;
-    display: flex;
-    align-items: center;
-    justify-content: space-between;
-    a {
-      display: flex;
-      align-items: center;
-      gap: 4px;
-      font-size: 14px;
-    }
-  }
-}
-</style>

+ 0 - 247
docs/src/assets/main.css

@@ -1,247 +0,0 @@
-*,
-:after,
-:before {
-  box-sizing: border-box;
-  border: 0 solid #e2e8f0;
-}
-
-:host,
-html {
-  line-height: 1.5;
-  -webkit-text-size-adjust: 100%;
-  -moz-tab-size: 4;
-  -o-tab-size: 4;
-  tab-size: 4;
-  font-family:
-    Inter var,
-    ui-sans-serif,
-    system-ui,
-    sans-serif,
-    Apple Color Emoji,
-    Segoe UI Emoji,
-    Segoe UI Symbol,
-    Noto Color Emoji;
-  font-feature-settings: normal;
-  font-variation-settings: normal;
-  -webkit-tap-highlight-color: transparent;
-}
-
-body {
-  margin: 0;
-  line-height: inherit;
-}
-
-hr {
-  height: 0;
-  color: inherit;
-  border-top-width: 1px;
-}
-
-abbr:where([title]) {
-  -webkit-text-decoration: underline dotted;
-  text-decoration: underline dotted;
-}
-
-a {
-  color: inherit;
-  text-decoration: inherit;
-}
-
-b,
-strong {
-  font-weight: bolder;
-}
-
-code,
-kbd,
-pre,
-samp {
-  font-family:
-    ui-monospace,
-    SFMono-Regular,
-    Menlo,
-    Monaco,
-    Consolas,
-    Liberation Mono,
-    Courier New,
-    monospace;
-  font-feature-settings: normal;
-  font-variation-settings: normal;
-  font-size: 1em;
-}
-
-small {
-  font-size: 80%;
-}
-
-sub,
-sup {
-  font-size: 75%;
-  line-height: 0;
-  position: relative;
-  vertical-align: baseline;
-}
-
-sub {
-  bottom: -0.25em;
-}
-
-sup {
-  top: -0.5em;
-}
-
-table {
-  text-indent: 0;
-  border-color: inherit;
-  border-collapse: collapse;
-}
-
-button,
-input,
-optgroup,
-select,
-textarea {
-  font-family: inherit;
-  font-feature-settings: inherit;
-  font-variation-settings: inherit;
-  font-size: 100%;
-  font-weight: inherit;
-  line-height: inherit;
-  letter-spacing: inherit;
-  color: inherit;
-  margin: 0;
-  padding: 0;
-}
-
-button,
-select {
-  text-transform: none;
-}
-
-button,
-input:where([type='button']),
-input:where([type='reset']),
-input:where([type='submit']) {
-  -webkit-appearance: button;
-  background-color: transparent;
-  background-image: none;
-}
-
-:-moz-focusring {
-  outline: auto;
-}
-
-:-moz-ui-invalid {
-  box-shadow: none;
-}
-
-progress {
-  vertical-align: baseline;
-}
-
-::-webkit-inner-spin-button,
-::-webkit-outer-spin-button {
-  height: auto;
-}
-
-[type='search'] {
-  -webkit-appearance: textfield;
-  outline-offset: -2px;
-}
-
-::-webkit-search-decoration {
-  -webkit-appearance: none;
-}
-
-::-webkit-file-upload-button {
-  -webkit-appearance: button;
-  font: inherit;
-}
-
-summary {
-  display: list-item;
-}
-
-blockquote,
-dd,
-dl,
-figure,
-h1,
-h2,
-h3,
-h4,
-h5,
-h6,
-hr,
-p,
-pre {
-  margin: 0;
-}
-
-fieldset {
-  margin: 0;
-}
-
-fieldset,
-legend {
-  padding: 0;
-}
-
-menu,
-ol,
-ul {
-  list-style: none;
-  margin: 0;
-  padding: 0;
-}
-
-dialog {
-  padding: 0;
-}
-
-textarea {
-  resize: vertical;
-}
-
-input::-moz-placeholder,
-textarea::-moz-placeholder {
-  opacity: 1;
-  color: #94a3b8;
-}
-
-input::placeholder,
-textarea::placeholder {
-  opacity: 1;
-  color: #94a3b8;
-}
-
-[role='button'],
-button {
-  cursor: pointer;
-}
-
-:disabled {
-  cursor: default;
-}
-
-audio,
-canvas,
-embed,
-iframe,
-img,
-object,
-svg,
-video {
-  display: block;
-  vertical-align: middle;
-}
-
-img,
-video {
-  max-width: 100%;
-  height: auto;
-}
-
-[hidden] {
-  display: none;
-}

+ 0 - 89
docs/src/components/DocsComp.vue

@@ -1,89 +0,0 @@
-<script lang="ts" setup>
-import { ref } from 'vue'
-import markdownit from 'markdown-it'
-import hljs from 'highlight.js'
-import 'highlight.js/styles/atom-one-light.css'
-
-const md: markdownit = markdownit({
-  highlight(str: string, lang: string) {
-    if (lang && hljs.getLanguage(lang)) {
-      try {
-        return `<pre><code class="hljs">${
-          hljs.highlight(str, { language: lang, ignoreIllegals: true }).value
-        }</code></pre>`
-      }
-      catch {
-        // do nothing
-      }
-    }
-
-    return `<pre><code class="hljs">${md.utils.escapeHtml(str)}</code></pre>`
-  },
-})
-
-const html = ref('')
-fetch('//cdn.jsdelivr.net/npm/chinese-days/README.md')
-  .then((response) => {
-    if (!response.ok) {
-      throw new Error(`Network response was not ok ${response.statusText}`)
-    }
-    return response.text()
-  })
-  .then((data) => {
-    html.value = md.render(data) as string
-    // console.log(data)
-  })
-  .catch((error) => {
-    console.error('There has been a problem with your fetch operation:', error)
-  })
-</script>
-
-<template>
-  <div class="markdown-body" v-html="html" />
-</template>
-
-<style>
-.markdown-body {
-  max-width: 700px;
-  padding: 0 20px;
-  margin: 0 auto;
-  text-align: left;
-  line-height: 1.7;
-  .hljs {
-    border-radius: 10px;
-    border: 1px solid #ddd;
-  }
-  h1,
-  h2,
-  h3,
-  h4,
-  h5,
-  h6,
-  p {
-    margin: 20px 0;
-  }
-  p {
-    & > img {
-      display: inline;
-    }
-    & > a {
-      display: inline;
-      & > img {
-        display: inline;
-      }
-    }
-  }
-  a {
-    text-decoration: underline;
-    display: inline;
-  }
-  ol,
-  ul {
-    padding-left: 20px;
-  }
-  li {
-    list-style: circle;
-    margin-bottom: 10px;
-  }
-}
-</style>

+ 0 - 6
docs/src/main.ts

@@ -1,6 +0,0 @@
-import './assets/main.css'
-
-import { createApp } from 'vue'
-import App from './App.vue'
-
-createApp(App).mount('#app')

+ 0 - 14
docs/tsconfig.app.json

@@ -1,14 +0,0 @@
-{
-  "extends": "@vue/tsconfig/tsconfig.dom.json",
-  "compilerOptions": {
-    "composite": true,
-    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
-
-    "baseUrl": ".",
-    "paths": {
-      "@/*": ["./src/*"]
-    }
-  },
-  "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
-  "exclude": ["src/**/__tests__/*"]
-}

+ 0 - 11
docs/tsconfig.json

@@ -1,11 +0,0 @@
-{
-  "references": [
-    {
-      "path": "./tsconfig.node.json"
-    },
-    {
-      "path": "./tsconfig.app.json"
-    }
-  ],
-  "files": []
-}

+ 0 - 19
docs/tsconfig.node.json

@@ -1,19 +0,0 @@
-{
-  "extends": "@tsconfig/node20/tsconfig.json",
-  "compilerOptions": {
-    "composite": true,
-    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
-
-    "module": "ESNext",
-    "moduleResolution": "Bundler",
-    "types": ["node"],
-    "noEmit": true
-  },
-  "include": [
-    "vite.config.*",
-    "vitest.config.*",
-    "cypress.config.*",
-    "nightwatch.conf.*",
-    "playwright.config.*"
-  ]
-}

+ 0 - 21
docs/vite.config.ts

@@ -1,21 +0,0 @@
-import { URL, fileURLToPath } from 'node:url'
-
-import { defineConfig } from 'vite'
-import vue from '@vitejs/plugin-vue'
-import VueDevTools from 'vite-plugin-vue-devtools'
-
-// https://vitejs.dev/config/
-export default defineConfig({
-  plugins: [
-    vue(),
-    VueDevTools(),
-  ],
-  resolve: {
-    alias: {
-      '@': fileURLToPath(new URL('./src', import.meta.url)),
-    },
-  },
-  define: {
-    chineseDays: 'window.chineseDays'
-  }
-})

+ 5 - 0
docs/zh/demo/calendar.md

@@ -0,0 +1,5 @@
+<script setup>
+  import Calendar from '../../components/calendar-comp.vue'
+</script>
+
+<Calendar lang="zh" />

+ 58 - 0
docs/zh/guide/24-solar-terms.md

@@ -0,0 +1,58 @@
+# 节气模块
+
+中国的二十四节气是传统的农业历法,它们标志着一年中不同的**时间段**。每个节气通常有特定的(开始)日期,但这个日期并不代表整个节气的持续时间。事实上,每个节气大约持续15天。
+
+以“小满”为例,它的日期通常在公历5月20日左右开始,但并不止于这一天,而是持续到下一个节气开始。具体来说,小满大约持续到6月5日(芒种)前后。因此,“小满”节气的时间段是从5月20日左右到6月5日左右。
+
+## 获取 24 节气的日期
+
+### 获取范围内节气日期数组
+
+```js
+import { getSolarTermsInRange } from "chinese-days";
+
+// 不传,查询当天
+console.log(getSolarTermsInRange())
+// [{date: '2024-05-29', term: 'lesser_fullness_of_grain', name: '小满', index: 10}]
+// index: 代表处于当前节气的第几天,从 1 开始
+
+// 不传end,查询指定日期
+console.log(getSolarTermsInRange('2024-05-01'))
+// [{date: '2024-05-01', term: 'grain_rain', name: '谷雨', index: 13}]
+
+// 查询范围内的节气
+console.log(getSolarTermsInRange('2024-05-01', '2024-05-06'))
+/**
+ * =>
+ * [
+ *   {"date":"2024-05-01","term":"grain_rain","name":"谷雨","index":13},
+ *   {"date":"2024-05-02","term":"grain_rain","name":"谷雨","index":14},
+ *   {"date":"2024-05-03","term":"grain_rain","name":"谷雨","index":15},
+ *   {"date":"2024-05-04","term":"grain_rain","name":"谷雨","index":16},
+ *   {"date":"2024-05-05","term":"the_beginning_of_summer","name":"立夏","index":1},
+ *   {"date":"2024-05-06","term":"the_beginning_of_summer","name":"立夏","index":2}
+ * ]
+ **/
+```
+
+### 如果你仅想获取节气**开始日期**数组
+
+```js
+import { getSolarTerms } from "chinese-days";
+
+/** 获取范围内 节气的开始日期数组 */
+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
+
+// 没有节气 返回 []
+getSolarTerms("2024-05-21", "2024-05-25");
+// return []
+
+/* 不传 end 参数, 获取某天 节气 */
+getSolarTerms("2024-05-20");
+// return: [{date: '2024-05-20', term: 'lesser_fullness_of_grain', name: '小满'}]
+```

+ 7 - 0
docs/zh/guide/contributing.md

@@ -0,0 +1,7 @@
+# 贡献代码
+
+1. Fork + Clone 项目到本地;
+2. 节假日: 修改 [节假日定义](https://github.com/vsme/chinese-days/blob/main/src/holidays/generate.ts);
+3. 农历定义: 修改 [农历定义](https://github.com/vsme/chinese-days/blob/main/src/solar_lunar/constants.ts);
+4. 其他修改...;
+5. 提交PR。

+ 11 - 0
docs/zh/guide/from-lunar.md

@@ -0,0 +1,11 @@
+# 农历转换阳历
+
+当为阴历闰月的时候,会出现一个农历日期对应两个阳历日期的情况,所以返回对象形式。
+
+```js
+console.log(getSolarDateFromLunar('2001-03-05'));
+// {date: '2001-03-29', leapMonthDate: undefined}
+
+console.log(getSolarDateFromLunar('2001-04-05'));
+// {date: '2001-04-27', leapMonthDate: '2001-05-27'}
+```

+ 59 - 0
docs/zh/guide/getting-started.md

@@ -0,0 +1,59 @@
+# 快速开始
+
+本文档内容主要针对 `JS` 和 `TS` 开发用户,使用其他语言请参考 [开发](/guide/what-is-chinese-days#非-js-语言)。
+
+## 推荐方式
+
+直接浏览器引入,更新较为及时:
+
+```html
+<!-- 引入 -->
+<script src="https://cdn.jsdelivr.net/npm/chinese-days"></script>
+
+<!-- 使用 -->
+<script>
+  chineseDays.isHoliday('2024-01-01');
+  // 或者解构使用
+  const { isHoliday } = chineseDays;
+</script>
+```
+
+或者指定 `type="module"`,使用 ESM:
+
+```html
+<script type="module">
+  import chineseDays from 'https://esm.run/chinese-days'
+  // 导入后使用
+  chineseDays.isHoliday('2024-01-01')
+</script>
+```
+
+## 安装方式
+
+```sh
+npm i chinese-days
+```
+
+使用 ESM 导入
+
+```ts
+import chineseDays from 'chinese-days';
+console.log(chineseDays);
+```
+
+在 Node 中使用
+
+```js
+const { isWorkday, isHoliday } = require('chinese-days');
+console.log(isWorkday('2020-01-01'));
+console.log(isHoliday('2020-01-01'));
+```
+
+## 指定版本
+
+一般不建议指定版本使用,因为节假日会随国务院发布进行更新;如一定要指定版本,具体使用方式可以参考 [jsdelivr](https://www.jsdelivr.com/),比如:
+
+```
+https://cdn.jsdelivr.net/npm/chinese-days@1.4.0
+https://esm.run/chinese-days@1.4.0
+```

+ 27 - 0
docs/zh/guide/holidays.md

@@ -0,0 +1,27 @@
+# 节假日
+
+## `isHoliday` 检查某个日期是否为节假日
+
+```js
+console.log(isHoliday('2023-01-01')); // true
+```
+
+## `getHolidaysInRange` 获取指定日期范围内的所有节假日
+
+接收起始日期和结束日期,并可选地决定是否包括周末。如果包括周末,则函数会返回包括周末在内的所有节假日;否则,只返回工作日的节假日。
+
+> tip: 即使不包括周末,周末的节假日仍然会被返回
+
+```js
+// 示例用法
+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)));
+```

+ 13 - 0
docs/zh/guide/lieu-days.md

@@ -0,0 +1,13 @@
+# 调休日
+
+## `isInLieu` 检查某个日期是否为调休日(in lieu day)
+
+在中国的节假日安排中,调休日是为了连休假期或补班而调整的工作日或休息日。例如,当某个法定假日与周末相连时,可能会将某个周末调整为工作日,或者将某个工作日调整为休息日,以便连休更多天。
+
+```js
+// 检查 2024-05-02 返回 `true` 则表示是一个调休日。
+console.log(isInLieu('2024-05-02')); // true
+
+// 检查 2024-05-01 返回 `false` 则表示不是一个调休日。
+console.log(isInLieu('2024-05-01')); // false
+```

+ 4 - 0
docs/zh/guide/thank.md

@@ -0,0 +1,4 @@
+# 致谢
+
+1. 农历数据来自于 [Bigkoo/Android-PickerView](https://github.com/Bigkoo/Android-PickerView) 项目。
+2. 中国节假日数据生成参考了 `Python` 版本的 [LKI/chinese-calendar](https://github.com/LKI/chinese-calendar) 项目。

+ 39 - 0
docs/zh/guide/to-lunar.md

@@ -0,0 +1,39 @@
+# 阳历农历互转
+
+特别说明,此库中:
+1. `2057-09-28` 为:农历丁丑(牛)年八月三十;
+2. `2097-08-07` 为:农历丁巳(蛇)年七月初一。
+
+## 阳历转换农历
+
+```js
+// 2097-8-7
+console.log(getLunarDate('2097-08-07'));
+
+// 2057-9-28
+console.log(getLunarDate('2057-09-28'));
+// {
+//   date: "2057-09-28",
+//   lunarYear: 2057,
+//   lunarMon: 8,
+//   lunarDay: 30,
+//   isLeap: false,
+//   lunarDayCN: "三十",
+//   lunarMonCN: "八月",
+//   lunarYearCN: "二零五七",
+//   yearCyl: "丁丑",
+//   monCyl: "己酉",
+//   dayCyl: "戊子",
+//   zodiac: "牛"
+// }
+
+// 非闰月 和 闰月例子
+console.log(getLunarDate('2001-04-27'));
+console.log(getLunarDate('2001-05-27'));
+```
+
+## 根据阳历日期区间,批量获取农历日期
+
+```js
+console.log(getLunarDatesInRange('2001-05-21', '2001-05-26'));
+```

+ 31 - 0
docs/zh/guide/what-is-chinese-days.md

@@ -0,0 +1,31 @@
+# 中国节假日
+
+## 介绍
+
+本项目提供了一系列用于查询中国节假日、调休日、工作日、24节气、以及农历阳历互转的函数,此外还支持 `iCal` 文件订阅节假日,可供 Google Calendar、Apple Calendar、Microsoft Outlook 等客户端订阅。
+
+每日会定时执行 `Github Action` 自动抓取数据,节假日变化时发送邮件提醒,信息会跟随国务院发布进行更新。
+
++ **节假日**:支持 2004年 至 2025年,包括 2020年 的春节延长
++ **24节气**:支持 1900年 至 2100年。
++ **农历日**:支持 1900年 至 2100年。
+
+项目主要针对 `JS` 或 `TS` 用户,使用方法可以看后续的文档。
+
+## 非 `JS` 语言
+
+如果你不使用 `JS` 或 `TS` 开发项目,本项目提供了中国节假日的 `JSON` 文件,通过链接 [chinese-days.json](https://cdn.jsdelivr.net/npm/chinese-days/dist/chinese-days.json) 可以直接引用。
+
+比如在 `Java` 中使用,可以参考 [Warnier-zhang/java-chinese-days](https://github.com/Warnier-zhang/java-chinese-days),仅用于查询中国节假日、调休日、工作日;
+
+## 日历订阅
+
+在 Google Calendar、Apple Calendar、Microsoft Outlook 等客户端中,可以设置订阅地址:[https://cdn.jsdelivr.net/npm/chinese-days/dist/holidays.ics](https://cdn.jsdelivr.net/npm/chinese-days/dist/holidays.ics) 来获取日历订阅。
+
+For English: [https://cdn.jsdelivr.net/npm/chinese-days/dist/holidays.en.ics](https://cdn.jsdelivr.net/npm/chinese-days/dist/holidays.en.ics)
+
+订阅的日历包含近三年(2023-2025年)的节假日和调休日。
+
+## 许可信息
+
+项目基于 MIT 许可发布。

+ 70 - 0
docs/zh/guide/working-days.md

@@ -0,0 +1,70 @@
+# 工作日
+
+## `isWorkday` 检查某个日期是否为工作日
+
+```js
+console.log(isWorkday('2023-01-01')); // false
+```
+
+## `getWorkdaysInRange` 取指定日期范围内的工作日列表
+
+接收起始日期和结束日期,并可选地决定是否包括周末。如果包括周末,则函数会返回包括周末在内的所有工作日;否则,只返回周一到周五的工作日。
+
+```js
+// 示例用法
+const start = '2024-04-26';
+const end = '2024-05-06';
+
+// 获取从 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);
+```
+
+## `findWorkday` 查找工作日
+
+查找从今天开始 未来的第 {deltaDays} 个工作日。
+
+```js
+// 查找从今天开始 未来的第 {deltaDays} 个工作日
+// 如果 deltaDays 为 0,首先检查当前日期是否为工作日。如果是,则直接返回当前日期。
+// 如果当前日期不是工作日,会查找下一个工作日。
+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);
+```
+
+## `getDayDetail` 获取日期信息
+
+函数用于检查指定日期是否是工作日,并返回一个是否工作日的布尔值和日期的详情。
+
+1. 如果指定日期是工作日,则返回 true 和工作日名称,如果是被调休的工作日,返回 true 和节假日详情。
+2. 如果是节假日,则返回 false 和节假日详情。
+
+```js
+// 示例用法
+
+// 正常工作日 周五
+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"}
+```

File diff suppressed because it is too large
+ 23 - 0
docs/zh/index.md


Some files were not shown because too many files changed in this diff