Skip to content

Commit

Permalink
Generate data through specific date instead of through file name
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kang8 committed Mar 27, 2023
1 parent 799b0b5 commit d45a3d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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 d45a3d2

Please sign in to comment.