I have a function to convert a date string with a specific format into a JS Date Object :
// param userInputBirthdate is a string with this format `dd.mm.yyyy`
function dateObjFromCHString(userInputBirthdate){
var paramDate = userInputBirthdate.split('.').reverse().join('-');
return new Date(paramDate);
}
when the user fill the birthDate input, the date object is created successfully by calling this function.
But now in my unit tests, I simulate the string given by the user with this code (I have to calculate the date like this for personal reasons, so please don't advise to simply write a string date constant) :
var localDateOptions = {month:'2-digit',year:'numeric',day:'2-digit'};
var today = new Date();
olderDate.setDate(today.getDate()-(25*365)); //25 years ago
olderDate = olderDate.toLocaleDateString('fr-CH',localDateOptions).replace(/\//g,'.');//return something like 23.03.1985
but now when I convert it with the function :
dateObjFromCHString(olderDate); //returns [date] Invalid Date in IE11
I get an "Invalid Date
" with IE (tested with IE11 edge mode), but everything works fine with FF, Chrome or Opera...
Can somebody tell me what is IE's problem ?
Note: I saw the other SO threads about this problem and the recommandation to use the format yyyy-mm-dd hh:mm:ss for the new Date param, but as it works with new Date('2012-03-11')
, I want to know why the unit test code does not work.