diff --git a/src/digital-components/date-picker/date-picker.vue b/src/digital-components/date-picker/date-picker.vue index fefeb30ff..e63349c67 100644 --- a/src/digital-components/date-picker/date-picker.vue +++ b/src/digital-components/date-picker/date-picker.vue @@ -193,6 +193,51 @@ export default { weekEndDate: weekEndDate, }); } + + // are any of these weeks split between two months? + const hasSplitWeek = (week) => { + return week.weekStartDate.getMonth() !== week.weekEndDate.getMonth() ? true : false; + }; + const splitWeekIndex = weeks.findIndex(hasSplitWeek); + + if (splitWeekIndex > -1) { + const week1 = []; + const week2 = []; + let switchToWeek2 = false; + + for (let j = 0; j < 7; j++) { + const newDate = new Date(weeks[splitWeekIndex].weekStartDate); + newDate.setDate(newDate.getDate() + j); + if (newDate.getDate() === 1) switchToWeek2 = true; + if (switchToWeek2) { + week2.push(newDate); + } else { + week1.push(newDate); + } + } + + const week1EndDate = week1[week1.length - 1]; + const week2StartDate = week2[0]; + + if (week1EndDate < today) { + // replace week 1 with week 2 + weeks[splitWeekIndex].weekStartDate = week2StartDate; + } else { + const newWeek = { + weekNum: weeks[splitWeekIndex].weekNum, + weekStartDate: week2StartDate, + weekEndDate: weeks[splitWeekIndex].weekEndDate, + }; + weeks[splitWeekIndex].weekEndDate = week1EndDate; + weeks.splice(splitWeekIndex + 1, 0, newWeek); + weeks.pop(); + weeks.forEach((item, index) => { + if (index > splitWeekIndex) { + item.weekNum = item.weekNum + 1; + } + }); + } + } return weeks; }, async loadInitialData(config) { @@ -222,8 +267,8 @@ export default { const initialViewStartDate = todayDate; const initialViewEndDate = initialViewWeeks[initialViewWeeks.length - 1].weekEndDate; - const saturday1month = initialViewWeeks[0].weekEndDate.getMonth(); - const sunday5month = + const firstSaturdayMonth = initialViewWeeks[0].weekEndDate.getMonth(); + const lastSundayMonth = initialViewWeeks[initialViewWeeks.length - 1].weekStartDate.getMonth(); let hideSomeDaysForInitialView = false; @@ -231,10 +276,10 @@ export default { // TODO - NEED TO CREATE OPPOSITE LOGIC FOR "past" DIRECTION LIKE BELOW vvvvv if (calendarViewDirection === "future") { - if (saturday1month !== sunday5month) { + if (firstSaturdayMonth !== lastSundayMonth) { hideSomeDaysForInitialView = true; } - if (initialViewStartDate.getMonth() === sunday5month) { + if (initialViewStartDate.getMonth() === lastSundayMonth) { hideSecondMonth = true; if (currentMonthEnd > initialViewEndDate) { // should part of 1st month be hidden?