Skip to content

Commit

Permalink
fix: fix an issue causing months to be skipped when navigating
Browse files Browse the repository at this point in the history
  • Loading branch information
Sqrrl committed Feb 5, 2024
1 parent c0dec2a commit e21bea2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-mice-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wc-datepicker': patch
---

Fix an issue causing months to be skipped when navigating
8 changes: 8 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
<script>
const datepicker = document.getElementById('datepicker');

datepicker.addEventListener('selectDate', (event) => {
console.log(event);
});

datepicker.addEventListener('changeMonth', (event) => {
console.log(event);
});

datepicker.disableDate = (date) =>
date.getDay() === 6 || date.getDay() === 0;
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/utils/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('format', () => {
);

expect(getNextMonth(new Date('2022-12-20'))).toEqual(
new Date('2023-01-20')
new Date('2023-01-01')
);
});

Expand All @@ -130,7 +130,7 @@ describe('format', () => {
);

expect(getPreviousMonth(new Date('2022-12-20'))).toEqual(
new Date('2022-11-20')
new Date('2022-11-01')
);
});

Expand Down
2 changes: 2 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function getNextDay(date: Date): Date {
export function getNextMonth(date: Date): Date {
const newDate = new Date(date);

newDate.setDate(1);
newDate.setMonth(newDate.getMonth() + 1);

return newDate;
Expand All @@ -131,6 +132,7 @@ export function getPreviousDay(date: Date): Date {
export function getPreviousMonth(date: Date): Date {
const newDate = new Date(date);

newDate.setDate(1);
newDate.setMonth(newDate.getMonth() - 1);

return newDate;
Expand Down

0 comments on commit e21bea2

Please sign in to comment.