Skip to content

docs(material/datepicker): add note about locale data in date-fns #24067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/material/datepicker/datepicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ export class MyApp {}

It's also possible to set the locale at runtime using the `setLocale` method of the `DateAdapter`.

**Note:** if you're using the `MatDateFnsModule`, you have to provide the data object for your
locale to `MAT_DATE_LOCALE` instead of the locale code, in addition to providing a configuration
compatible with `date-fns` to `MAT_DATE_FORMATS`. Locale data for `date-fns` can be imported
from `date-fns/locale`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also MAT_DATE_FORMATS to provide (Otherwise an error occurs: RangeError: Format string contains an unescaped latin alphabet character o). Full working example:

import { DateFnsAdapter, MAT_DATE_FNS_FORMATS } from '@angular/material-date-fns-adapter';
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core';
import { deAT } from 'date-fns/locale';

  { provide: DateAdapter, useClass: DateFnsAdapter },
  { provide: MAT_DATE_LOCALE, useValue: deAT },
  { provide: MAT_DATE_FORMATS, useValue: MAT_DATE_FNS_FORMATS },

<!-- example(datepicker-locale) -->

#### Choosing a date implementation and date format settings
Expand Down