material icon indicating copy to clipboard operation
material copied to clipboard

md-datepicker: Typed dates being parsed incorrectly in docs sample

Open stevenmiles opened this issue 11 years ago • 3 comments

My OS/Browser settings are set to UK date formats. Picking dates from the picker displays the dates in a UK format.

When typing a UK date into the date picker, its gets confused about how to interpret the date.

For instance,

  1. A UK date 23/08/2015 fails validation
  2. A UK date 12/08/2015 is parsed incorrectly. After opening, the calender shows 8th December 2015.

I'm guessing that is mandatory to set up $mdDateLocaleProvider? If so i guess that the sample in the docs should also do this.

I'm also confused about the date pickers interaction with angular i18n. The documentation for $mdDateLocaleProvider implies an entirely DIY approach regardless of angular i18n. Is that correct?.

stevenmiles avatar Sep 10 '15 07:09 stevenmiles

You should indeed be using $mdDateLocaleProvider in any real application. The default behavior, which relies on the native JS date parsing/formatting, isn't really appropriate for anything beyond a demo / toy.

Unfortunately, the native JS date parsing isn't locale-aware, which is why it doesn't understand UK dates. You're correct in that $mdDateLocaleProvider is very DIY; the idea was not to tie people into doing i18n via Angular when they may have different existing i18n approaches.

jelbourn avatar Sep 15 '15 18:09 jelbourn

This issue has been closed without resolution.

This issue was specifically about the samples in the documentation behaving incorrectly. Based on your reply, the samples should demonstrate the correct usage of $mdDateLocaleProvider (if for nothing else but to just to make them work). Thank you for clarifying the interaction with Angular i18n but this should not be closed as the samples have not been updated to behave correctly.

stevenmiles avatar Sep 16 '15 07:09 stevenmiles

Filed #4671 to track demo improvement.

jelbourn avatar Sep 16 '15 16:09 jelbourn