Skip to content

bug(datepicker): Localized date format issue #30910

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

Closed
LuisTovar0 opened this issue Apr 21, 2025 · 1 comment
Closed

bug(datepicker): Localized date format issue #30910

LuisTovar0 opened this issue Apr 21, 2025 · 1 comment
Labels
needs triage This issue needs to be triaged by the team

Comments

@LuisTovar0
Copy link

LuisTovar0 commented Apr 21, 2025

MatDatepicker seems to not accept dates in dd/mm/yyyy format, even when the MAT_DATE_LOCALE and DateAdapter's locale are set to a language/locale where this format is the standard.

I have noticed that this problem can be circumvented with the MomentJS date adapter for Angular, but it shouldn't be required since it's expected behaviour.

Reproduction

StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-4gjjc1ce?file=src%2Fapp%2Fapp.component.ts

Steps to reproduce:

  1. Select pt-PT or fr-FR
  2. Type "15/12/2024" in the datepicker and hit tab
  3. Now type "12/15/2024" and hit tab

Expected Behavior

In step 2, the datepicker should consider that a valid date
In step 3, the datepicker should not consider that a valid date

Actual Behavior

In step 2, the datepicker considers the date invalid
In step 3, the datepicker changes the string to 15/12/2024, making it become valid

Environment

Angular CLI: 19.2.7
CDK/Material:19.2.9
Node: 20.19.0
Package Manager: pnpm 8.15.6
OS: linux x64

@LuisTovar0 LuisTovar0 added the needs triage This issue needs to be triaged by the team label Apr 21, 2025
@crisbeto
Copy link
Member

This is due to the default date adapter. From the docs:

Please note: provideNativeDateAdapter is based off the functionality available in JavaScript's native Date object. Thus it is not suitable for many locales. One of the biggest shortcomings of the native Date object is the inability to set the parse format. We strongly recommend using an adapter based on a more robust formatting and parsing library. You can use provideMomentDateAdapter or a custom DateAdapter that works with the library of your choice.

You can provide an alternate adapter if you need something more robust: https://material.angular.io/components/datepicker/overview#choosing-a-date-implementation-and-date-format-settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue needs to be triaged by the team
Projects
None yet
Development

No branches or pull requests

2 participants