components icon indicating copy to clipboard operation
components copied to clipboard

datepicker: selects incorrect date for yyyy-mm-dd format

Open hblieb opened this issue 9 years ago • 2 comments

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Keying in, for example, 2017-06-30 should result in June 30th 2017 being selected in the calendar popup..

What is the current behavior?

Examples: Entering 2017-06-24 selects the 23rd Entering 2017-6-08 selects the 7th Entering 2017-06-08 selects the 7th Entering 2017-6-8 works correctly Entering 2017-06-8 works correctly

The problem only occurs when entry is in YYYY/MM/DD format and a 2-digit day is entered.

These other formats work correctly: mm-dd-yyyy (i.e. 6-30-2017) and dd-MMM-yyyy (i.e. 30-JUN-2017)

What are the steps to reproduce?

  • Go to https://material.angular.io/components/datepicker/overview, basic datepicker example
  • Key in 2017-06-30
  • Click the picker's icon
  • 6/29/2017 is selected

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Current version (Angular Material beta-8) at material.angular.io

Is there anything else we should know?

hblieb avatar Jul 28 '17 13:07 hblieb

The NativeDateAdapter is currently only able to parse mm-dd-yyyy due to limitations of JavaScript's Date object. We do have plans to make NativeDateAdapter more robust once the new i18n API arrives in Angular core (#6030). We also plan to add DateAdapters for libraries like Moment.js which give more control over the parse format (#5972). Neither of these is ready yet, if you need a quick solution immediately, I recommend extending NatvieDateAdapter and overriding the parse method to meet your needs.

Closing since #6030 is already tracking improved parsing in NativeDateAdapter

mmalerba avatar Jul 28 '17 17:07 mmalerba

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.