Skip to content

Commit 54e6674

Browse files
authored
fix(VCalendar): correct effective weekdays determination (#22042)
1 parent 977a7e2 commit 54e6674

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

packages/vuetify/src/labs/VCalendar/VCalendar.tsx

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
getEndOfMonth,
2525
getStartOfMonth,
2626
nextDay,
27-
parseTimestamp,
2827
prevDay,
2928
relativeDays,
3029
timestampToDate,
@@ -51,7 +50,6 @@ interface VCalendarRenderProps {
5150
end: CalendarTimestamp
5251
component: JSXComponent & { filterProps: <T>(props: T) => Partial<T> }
5352
maxDays: number
54-
weekdays: number[]
5553
categories: CalendarCategory[]
5654
}
5755

@@ -154,12 +152,6 @@ export const VCalendar = genericComponent<new (
154152
const lastStart = ref<CalendarTimestamp | null>(null)
155153
const lastEnd = ref<CalendarTimestamp | null>(null)
156154

157-
const parsedValue = computed((): CalendarTimestamp => {
158-
return (validateTimestamp(props.modelValue)
159-
? parseTimestamp(props.modelValue, true)
160-
: (base.parsedStart.value || base.times.today))
161-
})
162-
163155
const parsedCategoryDays = computed((): number => {
164156
return parseInt(String(props.categoryDays)) || 1
165157
})
@@ -169,10 +161,9 @@ export const VCalendar = genericComponent<new (
169161
})
170162

171163
const renderProps = computed((): VCalendarRenderProps => {
172-
const around = parsedValue.value
164+
const around = base.parsedValue.value
173165
let component: any = null
174166
let maxDays = props.maxDays
175-
let weekdays = base.parsedWeekdays.value
176167
let categories = parsedCategories.value
177168
let start = around
178169
let end = around
@@ -192,19 +183,12 @@ export const VCalendar = genericComponent<new (
192183
case 'day':
193184
component = VCalendarDaily
194185
maxDays = 1
195-
weekdays = [start.weekday]
196186
break
197187
case '4day':
198188
component = VCalendarDaily
199189
end = relativeDays(copyTimestamp(end), nextDay, 3)
200190
updateFormatted(end)
201191
maxDays = 4
202-
weekdays = [
203-
start.weekday,
204-
(start.weekday + 1) % 7,
205-
(start.weekday + 2) % 7,
206-
(start.weekday + 3) % 7,
207-
]
208192
break
209193
case 'custom-weekly':
210194
component = VCalendarWeekly
@@ -223,11 +207,6 @@ export const VCalendar = genericComponent<new (
223207
end = relativeDays(copyTimestamp(end), nextDay, days)
224208
updateFormatted(end)
225209
maxDays = days
226-
weekdays = []
227-
228-
for (let i = 0; i < days; i++) {
229-
weekdays.push((start.weekday + i) % 7)
230-
}
231210

232211
categories = getCategoryList(categories)
233212
break
@@ -236,11 +215,11 @@ export const VCalendar = genericComponent<new (
236215
throw new Error(`${type} is not a valid Calendar type`)
237216
}
238217

239-
return { component, start, end, maxDays, weekdays, categories }
218+
return { component, start, end, maxDays, categories }
240219
})
241220

242221
const eventWeekdays = computed((): number[] => {
243-
return renderProps.value.weekdays
222+
return base.effectiveWeekdays.value
244223
})
245224

246225
const categoryMode = computed((): boolean => {
@@ -287,7 +266,7 @@ export const VCalendar = genericComponent<new (
287266
}
288267

289268
function move (amount = 1): void {
290-
const moved = copyTimestamp(parsedValue.value)
269+
const moved = copyTimestamp(base.parsedValue.value)
291270
const forward = amount > 0
292271
const mover = forward ? nextDay : prevDay
293272
const limit = forward ? DAYS_IN_MONTH_MAX : DAY_MIN
@@ -402,7 +381,7 @@ export const VCalendar = genericComponent<new (
402381
})
403382

404383
useRender(() => {
405-
const { start, end, maxDays, component: Component, weekdays, categories } = renderProps.value
384+
const { start, end, maxDays, component: Component, categories } = renderProps.value
406385
return (
407386
<Component
408387
ref={ root }
@@ -413,7 +392,7 @@ export const VCalendar = genericComponent<new (
413392
start={ start.date }
414393
end={ end.date }
415394
maxDays={ maxDays }
416-
weekdays={ weekdays }
395+
weekdays={ base.effectiveWeekdays.value }
417396
categories={ categories }
418397
onClick:date={ (e: MouseEvent, day: CalendarTimestamp) => {
419398
if (attrs['onUpdate:modelValue']) emit('update:modelValue', day.date)
@@ -428,7 +407,6 @@ export const VCalendar = genericComponent<new (
428407
...base,
429408
lastStart,
430409
lastEnd,
431-
parsedValue,
432410
parsedCategoryDays,
433411
renderProps,
434412
eventWeekdays,

packages/vuetify/src/labs/VCalendar/composables/calendarBase.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export const makeCalendarBaseProps = propsFactory({
5959
}, 'VCalendar-base')
6060

6161
export interface CalendarBaseProps {
62+
modelValue?: string | number | Date
63+
categoryDays?: string | number
6264
start: string | number | Date
6365
end: string | number | Date | undefined
6466
weekdays: string | number[]
@@ -73,16 +75,6 @@ export function useCalendarBase (props: CalendarBaseProps) {
7375
const { times } = useTimes({ now: props.now })
7476
const locale = provideLocale(props)
7577

76-
const parsedWeekdays = computed((): number[] => {
77-
return Array.isArray(props.weekdays)
78-
? props.weekdays
79-
: (props.weekdays || '').split(',').map(x => parseInt(x, 10))
80-
})
81-
82-
const weekdaySkips = computed((): number[] => {
83-
return getWeekdaySkips(parsedWeekdays.value)
84-
})
85-
8678
const parsedStart = computed((): CalendarTimestamp => {
8779
if (props.type === 'month') {
8880
return getStartOfMonth(parseTimestamp(props.start, true))
@@ -101,6 +93,39 @@ export function useCalendarBase (props: CalendarBaseProps) {
10193
return value
10294
})
10395

96+
const parsedValue = computed((): CalendarTimestamp => {
97+
return (validateTimestamp(props.modelValue)
98+
? parseTimestamp(props.modelValue, true)
99+
: (parsedStart.value || times.today))
100+
})
101+
102+
const parsedWeekdays = computed((): number[] => {
103+
return Array.isArray(props.weekdays)
104+
? props.weekdays
105+
: (props.weekdays || '').split(',').map(x => parseInt(x, 10))
106+
})
107+
108+
const effectiveWeekdays = computed((): number[] => {
109+
const start = parsedValue.value
110+
const days = parseInt(String(props.categoryDays)) || 1
111+
112+
switch (props.type) {
113+
case 'day': return [start.weekday]
114+
case '4day': return [
115+
start.weekday,
116+
(start.weekday + 1) % 7,
117+
(start.weekday + 2) % 7,
118+
(start.weekday + 3) % 7,
119+
]
120+
case 'category': return Array.from({ length: days }, (_, i) => (start.weekday + i) % 7)
121+
default: return parsedWeekdays.value
122+
}
123+
})
124+
125+
const weekdaySkips = computed((): number[] => {
126+
return getWeekdaySkips(parsedWeekdays.value)
127+
})
128+
104129
const days = computed((): CalendarTimestamp[] => {
105130
return createDayList(
106131
parsedStart.value,
@@ -160,7 +185,9 @@ export function useCalendarBase (props: CalendarBaseProps) {
160185
return {
161186
times,
162187
locale,
188+
parsedValue,
163189
parsedWeekdays,
190+
effectiveWeekdays,
164191
weekdaySkips,
165192
parsedStart,
166193
parsedEnd,

packages/vuetify/src/labs/VCalendar/composables/calendarWithEvents.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export function useCalendarWithEvents (props: CalendarWithEventsProps, slots: an
204204
})
205205

206206
const eventWeekdays = computed((): number[] => {
207-
return base.parsedWeekdays.value
207+
return base.effectiveWeekdays.value
208208
})
209209

210210
function eventColorFunction (e: CalendarEvent): string | undefined {

0 commit comments

Comments
 (0)