Skip to content

Commit 623dff4

Browse files
authored
fix(DatePicker/DateRangePicker/Calendar/RangeCalendar)!: make weekStartsOn locale-independent (#2359)
1 parent c2b0fdd commit 623dff4

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

packages/core/src/date/comparators.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,13 @@ export function getLastFirstDayOfWeek<T extends DateValue = DateValue>(
143143
firstDayOfWeek: number,
144144
locale: string,
145145
): T {
146-
const day = getDayOfWeek(date, locale)
146+
/**
147+
* "firstDayOfWeek" is fixed to 0(Sunday) to avoid confusion regarding locales.
148+
* This also aligns with other date libraries, e.g., date-fns.
149+
*
150+
* #see https://github.com/unovue/reka-ui/issues/2157
151+
*/
152+
const day = getDayOfWeek(date, locale, 'sun')
147153

148154
if (firstDayOfWeek > day)
149155
return date.subtract({ days: day + 7 - firstDayOfWeek }) as T
@@ -159,7 +165,14 @@ export function getNextLastDayOfWeek<T extends DateValue = DateValue>(
159165
firstDayOfWeek: number,
160166
locale: string,
161167
): T {
162-
const day = getDayOfWeek(date, locale)
168+
/**
169+
* "firstDayOfWeek" is fixed to 0(Sunday) to avoid confusion regarding locales.
170+
* This also aligns with other date libraries, e.g., date-fns.
171+
*
172+
* #see https://github.com/unovue/reka-ui/issues/2157
173+
*/
174+
const day = getDayOfWeek(date, locale, 'sun')
175+
163176
const lastDayOfWeek = firstDayOfWeek === 0 ? 6 : firstDayOfWeek - 1
164177

165178
if (day === lastDayOfWeek)

0 commit comments

Comments
 (0)