

Ash made me consider not having my API accept Date instances at all, this would be easiest to validate.I also wonder whether there's a more elegant way. Borgar's solution does that, but I need to test it across browsers.

What I would prefer, if possible, is have my API accept a Date instance and to be able to check/assert whether it's valid or not.Ash recommended Date.parse for parsing date strings, which gives an authoritative way to check if the date string is valid.I'd like to tell the difference between valid and invalid date objects in JS, but couldn't figure out how: var d = new Date("foo") Ĭonsole.log(d.toString()) // shows 'Invalid Date'Ĭonsole.log(d instanceof Date) // shows 'true'Īny ideas for writing an isValidDate function?
