material icon indicating copy to clipboard operation
material copied to clipboard

md-datepicker date returned can be different if date entered as text or via calendar drop down

Open djmarcus1 opened this issue 11 years ago • 5 comments

Two issues.

[1] Selecting date via drop down shows a different value compared to entering same date as text.

I define (via .config of $mdDateLocaleProvider) a date format of YYYY-MM-DD.

I select a date via calendar drop down of October 1, 2015. ... the value returned is: 2015-10-01T04:00:00.000Z ... correct.

I enter a date via the text input: 10/01/2015 ... the value returned is: 2015-10-01T04:00:00.000Z ... also correct

I enter a date via the text input: 10-01-2015 ... the value returned is: 2015-10-01T04:00:00.000Z ... also correct

I enter a date via the text input: 2015/10/01 ... the value returned is: 2015-10-01T04:00:00.000Z ... also correct

So, it appears that the '/' and the '-' are interchangeable...

Note: I took the liberty of testing 'new Date(string)' directly to see if the problem was in the Date constructor.

new Date('2015/10/01') generated: 2015-10-01T04:00:00.000Z new Date('2015-10-01') generated: 2015-10-01T04:00:00.000Z

So the problem does not appear to be in the Date constructor.

BUT I enter a date via the text input: 2015-10-01 (which conforms to the 'YYYY-MM-DD' set in the .config) ... the value returned is: 2015-09-30T04:00:00.000Z ... WHICH IS WRONG!

The use of the '/' in the date works differently than using a '-' as a separator (remember, I used the '-' in the .config setting).

[2] Unrelated issue:

<md-datepicker ...></md-datepicker>  ... works

but

<md-datepicker .../>  does not work.

In the 'does not work case' the HTML after the datepicker is not recognized as such.

See codepen for demonstration of both issues: http://codepen.io/djmarcus/pen/RWpJNe

djmarcus1 avatar Oct 04 '15 02:10 djmarcus1

@djmarcus1 are you using a custom date parser/formatter with $mdDateLocaleProvider? If not, it's just using the browser's default parsing, which leave a lot to be desired.

jelbourn avatar Nov 02 '15 18:11 jelbourn

Yes, I am using a custom date formatter... see original post on Oct 3 (above).

I define (via .config of $mdDateLocaleProvider) a date format of YYYY-MM-DD.

djmarcus1 avatar Nov 02 '15 19:11 djmarcus1

+1

Hammild avatar Feb 29 '16 08:02 Hammild

+1

MariskaS avatar Mar 04 '16 08:03 MariskaS

+1

ghost avatar Mar 16 '16 20:03 ghost