-
-
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
fix: extra validation for dates #910
Conversation
This commit adds an additional test for dates over and above passing the pattern match. It checks to assertain that the date is a valid date. For examples, dates like 2009-02-29 are caught as invalid. Additionally, it also fixes a minor bug with the `weekDate` that was wrongfully leaving out W53 as an invalid date. fixes validatorjs#772
c75411b
to
e4bb296
Compare
@chriso - I hope this won't cause any major backward incompatibilities. I don't see the reason why someone would like to have something like However, I've added an option to turn this off instead with Let me know. |
test/validators.js
Outdated
@@ -5513,7 +5513,7 @@ describe('Validators', () => { | |||
'2009123', | |||
'2009-05', | |||
'2009-123', | |||
'2009-222', | |||
// '2009-222', // invalid test-case, implies 2009-22-2 |
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.
@chriso - I also found 2 invalid test cases in the cause of raising this PR, which I commented out. Let me know if this looks okay with you.
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 is a valid ordinal date. The 222 indicates that it's 222 days into the year.
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.
Happy to accept this one, but I'd make strict = false
by default so that it's backwards compatible.
We had a date validator in the past that did something similar (#418, #431) but it was a source of bugs and confusion. The ISO 8601 validator is a lot more strict in the types of dates it accepts, however the standard still defines many different types of dates and so we may inadvertently make it too strict.
Oops, I see, I did not take care of ordinal dates. Thanks for the catch! Let me refactor. |
@chriso - done, let me know. I've also included the previous tests when |
- adds provision for ordinal dates - checks that ordinal dates are also valid for leap years - includes regression tests for previous cases with `strict = false`
0c98d0d
to
f3bb0cd
Compare
This commit adds an additional test for dates
over and above passing the pattern match.
It checks to assertain that the date is a
valid date. For examples, dates like
2009-02-29 are caught as invalid.
Additionally, it also fixes a minor bug
with the
weekDate
that was wrongfullyleaving out W53 as an invalid date.
fixes #772