Skip to content
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
@oliverpool

Description

@oliverpool

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:

<LocalizationProvider key="localization-provider" dateAdapter={AdapterDateFns}>

// 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 the DateTimeControl component
  • how to map this string to a proper locale object

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions