material icon indicating copy to clipboard operation
material copied to clipboard

md-datepicker format

Open MariskaS opened this issue 10 years ago • 13 comments

Hello! When manually entering the date incorrectly displays the result - http://take.ms/mm0hr Tell me, please, what is the problem

MariskaS avatar Mar 04 '16 00:03 MariskaS

@MariskaS Can you please provide a demo for your issue?

devversion avatar Mar 04 '16 22:03 devversion

http://codepen.io/anon/pen/GZpeeL
how to reproduce the bug - http://take.ms/4BF9l

MariskaS avatar Mar 06 '16 00:03 MariskaS

I can't reproduce that bug. In my browser everything works as expected, the month and days are reflected because you specified the filter date:'dd/MM/yyyy'

devversion avatar Mar 06 '16 13:03 devversion

I manualy put date with format dd/MM/yyyy and I want to see date with the same format (I use filter date: dd/MM/yyyy). But I don't see wanted value. What's going on? md-datepicker locale issue 7404 angular_material - google chrome 2016-03-06 23 49 32 Please look again an example http://take.ms/1lmZj

MariskaS avatar Mar 06 '16 20:03 MariskaS

@DevVersion, I have reported this issue before, and also heard that you cant reproduce it.

I am wondering if you guys are sitting on a computer, localized to an area where the "other" dateformat is the default setting. In that case, it might be that this does not pop up as a problem for you.

We see the problem on all our devices - and we are sitting in Denmark, where DD/MM/YYYY is the default setting.

Link to duplicate issue, which still isn't resolved (but it is incorrecly marked as closed): https://github.com/angular/material/issues/6053

runethh avatar Mar 08 '16 07:03 runethh

Do you have the parseDate function set?

$mdDateLocaleProvider.parseDate = function(dateString) {
    var m = moment(dateString, 'D.M.YYYY', true);
    return m.isValid() ? m.toDate() : new Date(NaN);
};

chronixlo avatar Mar 14 '16 08:03 chronixlo

@runethh Is your issue the same as #7458.

topherfangio avatar Mar 17 '16 22:03 topherfangio

@topherfangio Yes, that appear to be the same issue

runethh avatar Mar 18 '16 09:03 runethh

hi,

recently got faced with this too. After looking to the code I think that DateLocaleProvider's defaultFormatDate and defaultParseDate are inconsistent: if we do use toLocaleDateString() in formatter then we also need to use fromLocaleString() when parsing user input :D

I know, there is not such function [yet] and new Date() expects standard formatted date, so we need to use the same default formatter without considering localization at all. For those who need the things to be localized there must be a ways to do it easily (eg using $mdDateLocaleProvider or even with angular i18n library)

Until input and output are consistent we have that we have: shown as d/M/y but input is required to be M/d/y which is misleading

djfd avatar Apr 10 '16 17:04 djfd

Yeah, I mentioned this in https://github.com/angular/material/issues/7456. If your default locale date format can't be parsed by new Date, then the value being set will be invalid. I've tried looking into this and it could be worked around relatively easily by having a test that checks which position the day, month and year are in, but I'm not sure how this would work with locales that don't use "regular" numbers (e.g. check the Arabic examples on the MDN article).

crisbeto avatar Apr 10 '16 17:04 crisbeto

@crisbeto why to embed i18n support to the core? strip it off from there, everybody who needs localization can use some means to achieve that

eg. there can be default @mdDateLocaleProvider init part in the material library checking if angular's core i18n library presents and taking the proper formats from there, defaulting to no-locale

djfd avatar Apr 10 '16 18:04 djfd

Well the the method for formatting the date can be overwritten, however I'd say that it makes sense that we shouldn't try to assume the date formatting. I'll look into it again.

crisbeto avatar Apr 10 '16 18:04 crisbeto

This issue is closed as part of our ‘Surge Focus on Material 2' efforts. For details, see our forum posting @ http://bit.ly/1UhZyWs.

ThomasBurleson avatar Jun 02 '16 07:06 ThomasBurleson