Skip to content

Commit

Permalink
Fix for #56
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogier Schouten committed May 6, 2021
1 parent f3c0abb commit 0fe27bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/basics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export function weekOfMonth(year: number, month: number, day: number): number {
// Last week of previous month
if (month > 1) {
// Default case
return weekOfMonth(year, month - 1, 31);
return weekOfMonth(year, month - 1, daysInMonth(year, month - 1));
} else {
// January
return weekOfMonth(year - 1, 12, 31);
Expand Down
4 changes: 4 additions & 0 deletions src/test/test-basics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ describe("weekOfMonth()", (): void => {
expect(basics.weekOfMonth(2016, 1, 3)).to.equal(5);
expect(basics.weekOfMonth(2016, 1, 4)).to.equal(1);
});

it("should not have issue #56", (): void => {
expect(basics.weekOfMonth(2021, 5, 1)).to.equal(5);
});
});

describe("secondsInDay()", (): void => {
Expand Down

0 comments on commit 0fe27bc

Please sign in to comment.