This is a migrated thread and some comments may be shown as answers.

DatePicker: bug in parsing date in 2-digits year format for February 29

1 Answer 390 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
David Rainton
Top achievements
Rank 1
David Rainton asked on 22 Nov 2014, 02:56 AM
It looks like there is a bug in parsing of dates in 2-digits year format ("yy") that affects keyboard input in the DatePicker widget. I created a simple example of the issue at http://dojo.telerik.com/agaNa. To reproduce the issue change string value to '2/29/2013' with keyboard (don't use popup calendar!). Click anywhere outside of the widget. Surprisingly the value is changed to '2/29/2020'. This is a quite unexpected behavior.

It looks like the reason is that I configured the widget to support both 4-digits and 2-digits year formats (specifically "M/d/yyyy" and "M/d/yy"). Obviously 2013 is not a leap year and there is no "February 29, 2013" but "February 29, 2020" is a valid date!

After some investigation I found that the issue seems to be in the kendo.parseDate: 

kendo.parseDate('2/29/2013', "M/d/yy")
kendo.parseDate('2/29/2013', ["M/d/yyyy", "M/d/yy"])

both return date "February 29, 2020" instead of null.

Is there a way to allow both 4- and 2-digits year formats in a DatePicker but avoid such an issue with "February 29"?

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 25 Nov 2014, 12:33 PM
Hello David,

Currently, the kendo.parseDate will successfully match the "20" string value from the provided year and thus will produce the dates shown in the example. For now, you will need to allow only dates with 4 digits, because there is no feasible way to avoid this behavior.

I've logged a Github issue for further investigation and we will try to find a proper solution of this discrepancy.

Best regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Date/Time Pickers
Asked by
David Rainton
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or