Skip to content

Commit

Permalink
Merge pull request #2 from kang8/bugfix/generate-data-through-specifi…
Browse files Browse the repository at this point in the history
…c-date
  • Loading branch information
kang8 committed Mar 29, 2023
2 parents 4db2ebb + d45a3d2 commit 1504e0b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kang8/chinese-holidays",
"version": "0.0.7",
"version": "0.0.8",
"description": "A lib provider api to check chinese holidays",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -18,6 +18,7 @@
"license": "MIT",
"devDependencies": {
"typescript": "^4.9.4",
"vite": "^4.2.1",
"vitest": "^0.25.7"
},
"dependencies": {
Expand Down
8 changes: 5 additions & 3 deletions src/holiday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ export class Holiday {
}

private parseYearJson(holiday_cn_json_schema: HolidayCnJsonSchema) {
const year: number = holiday_cn_json_schema.year
holiday_cn_json_schema.days.forEach((holiday_json: HolidayJson) => {
const year = new Date(holiday_json.date).getFullYear()

this.data[year] = new Map()
if (this.data[year] === undefined) {
this.data[year] = new Map()
}

holiday_cn_json_schema.days.forEach((holiday_json: HolidayJson) => {
this.data[year][holiday_json.date] = {
name: holiday_json.name,
type: holiday_json.isOffDay ? 'publicHoliday' : 'publicWorkday',
Expand Down
4 changes: 4 additions & 0 deletions test/holiday.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ describe('class', () => {
expect(holiday.isPublicHoliday(new Date('2023-10-1'))).toBe(true)
expect(holiday.publicHolidayName(new Date('2023-10-1'))).toBe('中秋节、国庆节')
})

it('2023-12-31 is public holiday', () => {
expect(holiday.isPublicHoliday(new Date('2022-12-31'))).toBe(true)
})
})

0 comments on commit 1504e0b

Please sign in to comment.