Skip to content

Commit

Permalink
Support year 2025
Browse files Browse the repository at this point in the history
  • Loading branch information
bastengao committed Dec 1, 2024
1 parent a7ff014 commit 8a4e412
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.7.0

Support year 2027 offline data.

# v1.6.0

Support year 2024 offline data.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ChineseHolidays.ready(options)

支持在线更新[节假日数据](https://github.com/bastengao/chinese-holidays-data),如果无法联网则使用本地打包的数据。

* [支持 2025 年](https://www.gov.cn/zhengce/content/202411/content_6986382.htm)
* [支持 2024 年](https://www.gov.cn/zhengce/content/202310/content_6911527.htm)
* [支持 2023 年](http://www.gov.cn/zhengce/content/2022-12/08/content_5730844.htm)
* [支持 2022 年](http://www.gov.cn/zhengce/content/2021-10/25/content_5644835.htm)
Expand Down
57 changes: 57 additions & 0 deletions data/2025.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"name": "元旦",
"range": ["2025-01-01"],
"type": "holiday"
},
{
"name": "春节",
"range": ["2025-01-26"],
"type": "workingday"
},
{
"name": "春节",
"range": ["2025-01-28", "2025-02-04"],
"type": "holiday"
},
{
"name": "春节",
"range": ["2025-02-08"],
"type": "workingday"
},
{
"name": "清明节",
"range": ["2025-04-04", "2025-04-06"],
"type": "holiday"
},
{
"name": "劳动节",
"range": ["2025-04-27"],
"type": "workingday"
},
{
"name": "劳动节",
"range": ["2025-05-01", "2025-05-05"],
"type": "holiday"
},
{
"name": "端午节",
"range": ["2025-05-31", "2025-06-02"],
"type": "holiday"
},
{
"name": "国庆节、中秋节",
"range": ["2025-09-28"],
"type": "workingday"
},
{
"name": "国庆节、中秋节",
"range": ["2025-10-01", "2025-10-08"],
"type": "holiday"
},
{
"name": "国庆节、中秋节",
"range": ["2025-10-11"],
"type": "workingday"
}
]
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chinese-holidays",
"version": "1.6.0",
"version": "1.7.0",
"description": "Chinese holidays",
"main": "lib/index.js",
"files": [
Expand Down
17 changes: 15 additions & 2 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const DataEndpoint = 'http://chinese-holidays-data.basten.me/data';
const IndexUrl = `${DataEndpoint}/index.json`;
const CacheDir = path.resolve(__dirname, '../cache');
const NewCacheDir = path.resolve(__dirname, '../cache_temp');
const version = '1.7.0';
const userAgent = `chinese-holidays-node/${version}`;

// TODO: checkUpdateInterval 检查更新周期

Expand Down Expand Up @@ -38,7 +40,13 @@ const Cache = {
console.log(`loading data from ${IndexUrl}`);
}

request(IndexUrl, (error, response, body) => {
const options = {
url: IndexUrl,
headers: {
'User-Agent': userAgent,
},
};
request(options, (error, response, body) => {
if (error) {
if (self.verbose) {
console.log(`load failed: ${error}`);
Expand Down Expand Up @@ -86,7 +94,12 @@ const Cache = {
if (self.verbose) {
console.log(`loading data from ${url}`);
}
const p = rq({ uri: url });
const p = rq({
uri: url,
headers: {
'User-Agent': userAgent,
},
});

p.then((body) => {
const filename = `${NewCacheDir}/${entry.year}.json`;
Expand Down

0 comments on commit 8a4e412

Please sign in to comment.