isDateString does not follow ISO-8601 ?
See original GitHub issueDate 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:11 (8 by maintainers)
Top Results From Across the Web
class-validator fails validation for IsDateString with 'must be ...
What's being logged in the error is not the object itself and turns out that mongoose will convert the date strings to date...
Read more >class-validator
Start using class-validator in your project by running `npm i class-validator`. There are 3967 other projects in the npm registry using ...
Read more >Check If a String Is a Valid Date in Java
In this tutorial, we'll discuss the various ways to check if a String contains a valid date in Java. We'll look at the...
Read more >Date Functions - Tableau
Supports ISO 8601 dates. A very similar calculation is DATENAME, which returns the name of the specified date part as a discrete string....
Read more >Managing date and time with PostgreSQL and TypeORM
By default, Postgres represents dates following the ISO 8601 standard. ... Using a date that does not apply to this format causes an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@cjancsar, recent changes with fix this validator are not yet available as the npm package.
@vlapo
@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,