Skip to content

Commit b9e654e

Browse files
Copilothotlong
andcommitted
Fix date mutation issues in CalendarView component
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 0ae91ff commit b9e654e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

packages/plugin-calendar/src/CalendarView.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ function getWeekStart(date: Date): Date {
189189
const d = new Date(date)
190190
const day = d.getDay()
191191
const diff = d.getDate() - day
192-
return new Date(d.setDate(diff))
192+
d.setDate(diff)
193+
return d
193194
}
194195

195196
function getMonthDays(date: Date): Date[] {
@@ -202,7 +203,7 @@ function getMonthDays(date: Date): Date[] {
202203

203204
// Add previous month days
204205
for (let i = startDay - 1; i >= 0; i--) {
205-
const prevDate = new Date(firstDay)
206+
const prevDate = new Date(firstDay.getTime())
206207
prevDate.setDate(prevDate.getDate() - (i + 1))
207208
days.push(prevDate)
208209
}
@@ -215,7 +216,7 @@ function getMonthDays(date: Date): Date[] {
215216
// Add next month days
216217
const remainingDays = 42 - days.length
217218
for (let i = 1; i <= remainingDays; i++) {
218-
const nextDate = new Date(lastDay)
219+
const nextDate = new Date(lastDay.getTime())
219220
nextDate.setDate(nextDate.getDate() + i)
220221
days.push(nextDate)
221222
}

0 commit comments

Comments
 (0)