This repository was archived by the owner on Sep 9, 2024. It is now read-only.
This repository was archived by the owner on Sep 9, 2024. It is now read-only.
Setup AdapterDateFns with current locale #1081
Closed
Description
Currently the date picker always show AM/PM, which is unusual for non-english people.
Digging in the code, it seems that mui-x is using the en-US
is locale
is not set: https://github.com/mui/mui-x/blob/603e688d3a55740578dcd193e59063ce7bdab389/packages/x-date-pickers/src/AdapterDateFnsBase/AdapterDateFnsBase.ts#L224
public is12HourCycleInCurrentLocale = () => {
if (this.locale) {
return /a/.test(this.locale.formatLong!.time({ width: 'short' }));
}
// By default, date-fns is using en-US locale with am/pm enabled
return true;
};
It would be nice with the locale
setting could be set on date-fns:
// with date-fns v2.x
import locales from 'date-fns/locale';
const current_locale = locales[config.locale] ?? null; // logic could be improved?
<LocalizationProvider dateAdapter={AdapterDateFns} adapterLocale={current_locale}>
I would be ready to make a PR, however I don't know:
- how to get the global
locale
config value into theDateTimeControl
component - how to map this string to a proper
locale
object
What do you think?