diff --git a/packages/nc-gui/components/nc/DatePicker.vue b/packages/nc-gui/components/nc/DatePicker.vue index 53ed627351..946962e9f5 100644 --- a/packages/nc-gui/components/nc/DatePicker.vue +++ b/packages/nc-gui/components/nc/DatePicker.vue @@ -34,16 +34,51 @@ const currentMonth = computed(() => { }); const getDay = (date: Date) => { - return date.getDate(); + return date.getDay(); }; -const blankDays = computed((): any => { +const blankDaysAtStart = computed((): any => { const date = new Date(pageDate.value); const dObj = new Date(date.getFullYear(), date.getMonth(), 1, date.getHours(), date.getMinutes()); - if (props.isMondayFirst) { - return getDay(dObj) > 0 ? getDay(dObj) - 1 : 6; + + const blankDaysCount = props.isMondayFirst + ? getDay(dObj) > 0 + ? getDay(dObj) - 1 + : 6 + : getDay(dObj); + + const blankDays = []; + + for (let i = 1; i <= blankDaysCount; i++) { + const blankDayDate = new Date(dObj); + blankDayDate.setDate(dObj.getDate() - i); + const dayOfMonth = blankDayDate.getDate(); + blankDays.unshift({ day: dayOfMonth }); + } + + return blankDays; +}); + +const blankDaysAtEnd = computed((): any => { + const date = new Date(pageDate.value); + const lastDayOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0); + + const daysInWeek = 7; + const lastDayOfWeek = props.isMondayFirst ? 6 : 0; + + const blankDaysCount = props.isMondayFirst + ? lastDayOfWeek - (lastDayOfMonth.getDay() % daysInWeek) + : (daysInWeek - 1) - lastDayOfMonth.getDay(); + + const blankDays = []; + + for (let i = 1; i <= blankDaysCount; i++) { + const blankDayDate = new Date(lastDayOfMonth); + blankDayDate.setDate(lastDayOfMonth.getDate() + i); + const dayOfMonth = blankDayDate.getDate(); + blankDays.push({ day: dayOfMonth }); } - return getDay(dObj); + return blankDays; }); function isSelectedDate(dObj: Date): boolean { @@ -129,7 +164,7 @@ const selectDate = (day: number) => { {{ day }}