-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Leap year and general date validation for isDate(). #431
Conversation
07fcb25
to
31fbd30
Compare
I'm a little bit wary of merging this considering how lenient |
31fbd30
to
25b835e
Compare
25b835e
to
4beed24
Compare
@chriso Just thought I'd let you know that the ISO 8601 dates in the test suite mismatch in some places with the JavaScript definition of valid date. For example, these are all valid ISO 8601 dates but invalid JavaScript dates:
And these are valid JavaScript dates but invalid ISO 8601 dates:
I've updated my tests with ISO 8601 dates accordingly. I'm sure I need more, but I'd love suggestions as to what type of tests to add. |
Awesome, thanks. Going by these Not sure if this is a valid timezone offset or not, but
|
return false; | ||
} | ||
if (typeof str !== 'string') { | ||
return true; //if Date.parse() passes, it's the current time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary. The first argument is always coerced to a string (1, 2, 3) based on these rules: https://github.com/chriso/validator.js#strings-only
I borrowed some RFC 2822 tests from around the web - I figured it'd be slightly better than trying myself - and I removed tests and checks for non-string types. I also made sure to only check against actual double digit numbers, so that example you posted should pass. |
LGTM, thanks! |
Leap year and general date validation for isDate().
This is a follow up from #418. The one gotcha is that it doesn't accept
null
as valid which the Date function does. However, this works just fine when I test the function by itself; it may just be an artifact of the testing suite.Let me know if you'd like to see more tests.