Anil
Anil

Reputation: 349

Date.parse() false positives

In code below, I don't want the string not_a_date to be whitelisted as a proper date, but rather as NaN or invalid date. but Date.parse returns a proper epoch value.

not_a_date = 'https://www.example.com/2021/03/03'
Date.parse(not_a_date)
// Expected: NaN
// Result: 1614709800000

Upvotes: 0

Views: 111

Answers (1)

user17487781
user17487781

Reputation:

Date.parse is still largely dependant on the browser you're using; your code DOES return NaN in Firefox v94 for example. You'll likely have to write your own parsing function before passing it to Date.parse().

Upvotes: 1

Related Questions