From 799b0b5d73740798cbcfad5134827ec7edb22f32 Mon Sep 17 00:00:00 2001 From: kang Date: Fri, 24 Mar 2023 15:14:17 +0800 Subject: [PATCH 1/2] vitest depends on vite --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index af10808..c10f026 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "license": "MIT", "devDependencies": { "typescript": "^4.9.4", + "vite": "^4.2.1", "vitest": "^0.25.7" }, "dependencies": { From d45a3d2924a939b0e51c2e0f72e2ff19f7ae4963 Mon Sep 17 00:00:00 2001 From: kang Date: Fri, 24 Mar 2023 15:15:20 +0800 Subject: [PATCH 2/2] Generate data through specific date instead of through file name In upstream data, the New Year's Day holiday is included in the file for the next year. For example, '2022-12-31' would be in 2023.json. This will result in incorrect data being generated through the file name. Fixed: #1 --- src/holiday.ts | 8 +++++--- test/holiday.test.ts | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) 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) + }) })