Recently, Luxon added support for localized week information. I updated my version of Luxon to the latest release that contains this update, 3.4.4
but when opening up the calendar, the week still starts on Monday instead of Sunday.
I would assume that the LuxonAdapter
would pick up the changes and use the localized week data but it doesn't seem to be any different.
My package.json
has the latest versions of both libraries:
"@mui/x-date-pickers": "^7.0.0-alpha.0",
"luxon": "^3.4.4",
Then, in my App.tsx
I add the LocalizationProvider
with the LuxonAdapter
:
import { LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterLuxon } from "@mui/x-date-pickers/AdapterLuxon";
<LocalizationProvider dateAdapter={AdapterLuxon}>
<Outlet />
</LocalizationProvider>
Lastly, the DateCalendar
component:
import { DateTime } from "luxon";
import { DateCalendar } from "@mui/x-date-pickers";
const [calendarValue, setCalendarValue] = useState<DateTime | null>(DateTime.now());
<DateCalendar
value={calendarValue}
onChange={setCalendarValue}
views={["day"]}
disablePast
sx={{ m: 0 }}
/>
I see you currently have:
Verify first that Luxon is configured with the correct locale that starts the week on Sunday. If your locale is set to one where the week traditionally starts on Monday, Luxon will follow that setting.
If the LuxonAdapter does not automatically pick the start of the week from Luxon settings, you might need to configure it explicitly. But I do not see a way to do this directly in
@mui/x-date-pickers
.mui/material-ui
issue 30591 proposes, on a similar issue referenced bymoment/luxon
issue 1447 (the very issue yourmoment/luxon
PR 1454 fixes)The custom adapter factory function
adapterLuxonFactory
takes aweekStartsOn
parameter (number representing the day the week starts on, with1
for Monday,2
for Tuesday, up to7
for Sunday). That function is used in theLocalizationProvider
to make sure the entire calendar component respects the specified start of the week.To integrate this solution into your current setup, you would replace, for testing, the standard
LuxonAdapter
with this custom adapter, by modifying theLocalizationProvider
in yourApp.tsx
to use this custom adapter.Make sure you provide the correct
weekStartsOn
value when initializing the adapter. For starting the week on Sunday, this would be7
.I also see
mui/mui-x
issue 9984, which says:This is discussed in
mui/mui-x
issue 10805: "[pickers]
Support changing start of week day on AdapterLuxon"This is
mui/mui-x
PR 10964