From e21bea26065bf1f07659b8bcc03b630c45388f46 Mon Sep 17 00:00:00 2001 From: Philipp Siekmann Date: Mon, 5 Feb 2024 09:10:25 +0100 Subject: [PATCH] fix: fix an issue causing months to be skipped when navigating --- .changeset/poor-mice-breathe.md | 5 +++++ src/index.html | 8 ++++++++ src/utils/utils.spec.ts | 4 ++-- src/utils/utils.ts | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/poor-mice-breathe.md diff --git a/.changeset/poor-mice-breathe.md b/.changeset/poor-mice-breathe.md new file mode 100644 index 0000000..be44493 --- /dev/null +++ b/.changeset/poor-mice-breathe.md @@ -0,0 +1,5 @@ +--- +'wc-datepicker': patch +--- + +Fix an issue causing months to be skipped when navigating diff --git a/src/index.html b/src/index.html index fcb1b33..4e6059d 100644 --- a/src/index.html +++ b/src/index.html @@ -23,6 +23,14 @@ diff --git a/src/utils/utils.spec.ts b/src/utils/utils.spec.ts index 20f0451..02a2332 100644 --- a/src/utils/utils.spec.ts +++ b/src/utils/utils.spec.ts @@ -105,7 +105,7 @@ describe('format', () => { ); expect(getNextMonth(new Date('2022-12-20'))).toEqual( - new Date('2023-01-20') + new Date('2023-01-01') ); }); @@ -130,7 +130,7 @@ describe('format', () => { ); expect(getPreviousMonth(new Date('2022-12-20'))).toEqual( - new Date('2022-11-20') + new Date('2022-11-01') ); }); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index f997f71..b46ba9b 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -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; @@ -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;