Date strings with negative TZ offsets are not considered valid with current regex
Think it's missing negative offsets and handling single-digit hours
2016-07-16T19:20:30+5:30 no match
2016-07-16T19:20:30+05:30 match
2019-09-03T20:16:24-01:00 no match
2019-09-03T20:16:24+01:00 match
I think they should all match as valid iso strings, not too sure
Current regex testing those strings - https://regex101.com/r/RzcfrV/2/
Hapijs's joi (2.5M weekly downloads) is using the following regex
^(?:[-+]\d{2})?(?:\d{4}(?!\d{2}\b))(?:(-?)(?:(?:0[1-9]|1[0-2])(?:\1(?:[12]\d|0[1-9]|3[01]))?|W(?:[0-4]\d|5[0-2])(?:-?[1-7])?|(?:00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[1-6])))(?![T]$|[T][\d]+Z$)(?:[T\s](?:(?:(?:[01]\d|2[0-3])(?:(:?)[0-5]\d)?|24\:?00)(?:[.,]\d+(?!:))?)(?:\2[0-5]\d(?:[.,]\d+)?)?(?:[Z]|(?:[+-])(?:[01]\d|2[0-3])(?::?[0-5]\d)?)?)?)?$
https://github.com/hapijs/joi/blob/e3e7626b39625c38a71f3b06665142ec0a29bac6/lib/common.js#L13
https://regex101.com/r/99Uj49/1/
Happy to make a PR to switch to Hapi's regex if it's correct.
Hi @jacktuck,
We are open to PR with fix and of course do not forget tests.
@vlapo however validatorjs seems to have another regex https://github.com/validatorjs/validator.js/blob/master/src/lib/isISO8601.js
So why we have isDateString and also isISO8601 validators? :) Looks like isDateString should be just alias for isISO8601. @rubiin thnx for the point us to this.
@jacktuck what do you think?
@vlapo I must have missed the isISO8601 validator. Agree that isDateString should be an alias for isISO8601. Unless there is some important distinction that mean we'd want both.
Assumming the regex applied, both of them seem to be different. However we can still use the validatorjs's regex on isdatestring @vlapo
Currently unable to get dates to validate with either isDateString and IsISO8601
Okey after small research I think we have some duplicity and missing functionality/lack of docs.
isDateString validator should be "alias" for isISO8601 not some kind of magic regexp in our codebase - looks like merging https://github.com/typestack/class-validator/pull/88 was not a good idea. But I think we should keep this alias as it is more suggestive validator name than isISO8601isISO8601 accepts also "only date string" inputs as 2019-04-04 - https://github.com/typestack/class-validator/issues/407strict option parameter in isISO8601isRFC3339 validator as RFC3339 is also date format standard - validatorjsMerging #88 was a really not a good idea(
Issues for isDateString:
I think we can fix the isDateString validator and the isISO8601 validator for a start.
And we will make some update for support "only date string" inputs as "2019-04-04" after solving https://github.com/validatorjs/validator.js/issues/1130
We have the IsISO8601 decorator, now. I think using isDateString and isISO8601 alias for the same functionality is not a good idea. What about you? @vlapo @rubiin
@ihorTymofieiev none of these date validators seem to currently work with actual ISO8601 strings. Is there any PR that can be merged to resolve this? Or can I assist somehow? Dates are pretty much broken right now,
@cjancsar, recent changes with fix this validator are not yet available as the npm package.
@vlapo
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@ihorTymofieiev none of these date validators seem to currently work with actual ISO8601 strings. Is there any PR that can be merged to resolve this? Or can I assist somehow? Dates are pretty much broken right now,