diff --git a/package.json b/package.json index af10808..3a6fdc7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -18,6 +18,7 @@ "license": "MIT", "devDependencies": { "typescript": "^4.9.4", + "vite": "^4.2.1", "vitest": "^0.25.7" }, "dependencies": { diff --git a/src/holiday.ts b/src/holiday.ts index 2d45dbe..8272fa4 100644 --- a/src/holiday.ts +++ b/src/holiday.ts @@ -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', diff --git a/test/holiday.test.ts b/test/holiday.test.ts index c9a6b14..df9d1af 100644 --- a/test/holiday.test.ts +++ b/test/holiday.test.ts @@ -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) + }) })