refactor: adjust calendar start date calculation to handle week alignment correctly
This commit is contained in:
parent
f55c72b535
commit
6b2af762f9
|
@ -2,8 +2,11 @@ export default (currentDate: number, currentYear: number): Date[] => {
|
||||||
const baselineDate = new Date(currentYear, currentDate)
|
const baselineDate = new Date(currentYear, currentDate)
|
||||||
|
|
||||||
const calendarStart = new Date(baselineDate.getFullYear(), baselineDate.getMonth(), 1)
|
const calendarStart = new Date(baselineDate.getFullYear(), baselineDate.getMonth(), 1)
|
||||||
if (calendarStart.getDay() !== 1)
|
|
||||||
calendarStart.setDate(calendarStart.getDate() - calendarStart.getDay() + 1)
|
const dayOfWeek = calendarStart.getDay() === 0 ? 7 : calendarStart.getDay()
|
||||||
|
|
||||||
|
if (dayOfWeek !== 1)
|
||||||
|
calendarStart.setDate(calendarStart.getDate() - dayOfWeek + 1)
|
||||||
|
|
||||||
const calendarEnd = new Date(baselineDate.getFullYear(), baselineDate.getMonth() + 1, 0)
|
const calendarEnd = new Date(baselineDate.getFullYear(), baselineDate.getMonth() + 1, 0)
|
||||||
if (calendarEnd.getDay() !== 0)
|
if (calendarEnd.getDay() !== 0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user