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

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 8, 2021

Adds a note about how locale data should be provided for users that consume the date-fns adapter.

Fixes #24026.

@crisbeto crisbeto added merge safe P4 A relatively minor issue that is not relevant to core functions target: patch This PR is targeted for the next patch release labels Dec 8, 2021
@crisbeto crisbeto requested a review from mmalerba December 8, 2021 16:14
**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. 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 },

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 29, 2021
@andrewseguin
Copy link
Contributor

@crisbeto - is this one ready for review?

Adds a note about how locale data should be provided for users that consume the `date-fns` adapter.

Fixes angular#24026.
@crisbeto crisbeto force-pushed the 24026/date-fns-locale-data branch from c2d24ca to 330265a Compare February 25, 2022 20:42
@crisbeto
Copy link
Member Author

This should be good to go @andrewseguin

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Mar 14, 2022
@zarend zarend merged commit cbef92a into angular:master Mar 14, 2022
zarend pushed a commit that referenced this pull request Mar 14, 2022
…4067)

Adds a note about how locale data should be provided for users that consume the `date-fns` adapter.

Fixes #24026.

(cherry picked from commit cbef92a)
forsti0506 pushed a commit to forsti0506/components that referenced this pull request Apr 3, 2022
…gular#24067)

Adds a note about how locale data should be provided for users that consume the `date-fns` adapter.

Fixes angular#24026.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P4 A relatively minor issue that is not relevant to core functions target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(material-date-fns-adapter): Wrong option for format method
6 participants