bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Bad resulting dates when typing incorrect date formats

Open emb opened this issue 11 years ago • 4 comments

Libraries

  1. Angular: 1.2.28
  2. Bootstrap: 0.12.0

Test Case

  1. Set datepicker format dd/MM/yyyy
  2. 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

emb avatar Jan 16 '15 03:01 emb

I noticed in Firefox a date like 27/29/1956 is valid and converted to March 29th 1956.

emb avatar Feb 19 '15 01:02 emb

+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.

mirow avatar Apr 09 '15 12:04 mirow

suspect that this is now fixed on master if you'd like to give the bleeding edge a try

karianna avatar Apr 09 '15 14:04 karianna

Here's a plunk with the latest version from master demonstrating the problem.

RobJacobs avatar Apr 09 '15 15:04 RobJacobs