Skip to content

Commit

Permalink
fixedDate should be at time 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythe1337N committed Feb 24, 2023
1 parent 8f6f664 commit 94dbbd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export function firstOfWeekdayAfterDate(weekday: Weekday, refDate: Date) {

export function fixedDate(date: Date) {
const d = new Date(date);
d.setMilliseconds(0);
d.setSeconds(0);
d.setMinutes(0);
d.setHours(0);
d.setMinutes(-d.getTimezoneOffset());
return d;
}
Expand Down
11 changes: 8 additions & 3 deletions tests/swedish-holidays.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ test('Should throw an error if year is out of range', () => {
});

test('isPublicHoliday should be true for sundays', () => {
const saturdayIsNotPublicHoliday = isPublicHoliday(new Date('2021-11-13'));
const sundayIsPublicHoliday = isPublicHoliday(new Date('2021-11-14'));
const mondayIsNotPublicHoliday = isPublicHoliday(new Date('2021-11-15'));
const saturdayIsNotPublicHoliday = isPublicHoliday(new Date('2021-11-13T01:23:45.678Z'));
const sundayIsPublicHoliday = isPublicHoliday(new Date('2021-11-14T01:23:45.678Z'));
const mondayIsNotPublicHoliday = isPublicHoliday(new Date('2021-11-15T01:23:45.678Z'));
assert.strictEqual(saturdayIsNotPublicHoliday, false);
assert.strictEqual(sundayIsPublicHoliday, true);
assert.strictEqual(mondayIsNotPublicHoliday, false);
});

test('isPublicHoliday should be true for christmas day', () => {
const christmas = isPublicHoliday(new Date('2021-12-25T01:23:45.678Z'));
assert.strictEqual(christmas, true);
});

0 comments on commit 94dbbd9

Please sign in to comment.