material icon indicating copy to clipboard operation
material copied to clipboard

Unexpected Behavior on <md-datepicker> With YYYY-MM-DD Format

Open abouillon opened this issue 10 years ago • 4 comments

While working with the datepicker component to see which formats are accepted as valid date formats I found this behavior. When using the text input to enter a date in yyyy-mm-dd format it will roll the date back 1 day. So if you type 2016-04-05 into the input this will result in 4/4/2016 being displayed.

https://plnkr.co/edit/Vb43PW

abouillon avatar Apr 22 '16 17:04 abouillon

I couldn't reproduce it. It showed up as 4/5/16 for me.

crisbeto avatar Apr 22 '16 18:04 crisbeto

This is a pickle then because I am at a loss as to what is different on my end that could be causing this because this also happens on the demo.

http://i.imgur.com/2J97hT5.gifv

abouillon avatar Apr 22 '16 18:04 abouillon

The date from the view gets passed through the parseDate method on the $mdDateLocaleProvider before it gets assigned to the modal. You can override this method if you want more control over what gets inserted. You can read more about it in the docs.

crisbeto avatar Apr 22 '16 19:04 crisbeto

This happens when your timezone is under GMT and YYYY-MM-DD is the ISO 8601. So the browser will interpret it as the date you entered(Month Day Year 00:00:00) minus the difference of hours of the timezone. I still believe its an issue in datepicker.

slimovic avatar Jun 03 '16 15:06 slimovic