Bad resulting dates when typing incorrect date formats
Libraries
- Angular: 1.2.28
- Bootstrap: 0.12.0
Test Case
- Set datepicker format
dd/MM/yyyy - Type a date with a single digit month (notice bad-formatted date). Example: 04/1/2015
Expected Results
Invalid date. Or at least a date corresponding to the 4th of January 2015.
Observed Results
The date we find in the model is 1st of April 2015. This is obviously an incorrect date.
Working Example
http://plnkr.co/edit/3VHHBX?p=preview
I noticed in Firefox a date like 27/29/1956 is valid and converted to March 29th 1956.
+1 The offending line in the code is:
var date = dateParser.parse(viewValue, dateFormat) || new Date(viewValue);
So if the date doesn't match the given format, bootstrap tests whether the value happens to produce a valid js date, which of course it shouldn't try to do at all.
suspect that this is now fixed on master if you'd like to give the bleeding edge a try
Here's a plunk with the latest version from master demonstrating the problem.