Skip to content

isDateString does not follow ISO-8601 ? #412

Closed

Description

@jacktuck

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.

Activity

  1. changed the title [-]isDateString does not follow ISO-8601 [/-] [+]isDateString does not follow ISO-8601 ?[/+] on Sep 3, 2019
  2. vlapo commented on Sep 24, 2019

    @vlapo
    Contributor

    Hi @jacktuck,

    We are open to PR with fix and of course do not forget tests.

  3. added
    type: fix
    on Sep 24, 2019
  4. rubiin commented on Sep 25, 2019

    @rubiin
    Contributor
  5. vlapo commented on Sep 25, 2019

    @vlapo
    Contributor

    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?

  6. jacktuck commented on Sep 25, 2019

    @jacktuck
    Author

    @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.

  7. rubiin commented on Sep 25, 2019

    @rubiin
    Contributor

    Assumming the regex applied, both of them seem to be different. However we can still use the validatorjs's regex on isdatestring @vlapo

  8. joseym commented on Oct 8, 2019

    @joseym

    Currently unable to get dates to validate with either isDateString and IsISO8601

  9. vlapo commented on Oct 14, 2019

    @vlapo
    Contributor

    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 validate date iso string #88 was not a good idea. But I think we should keep this alias as it is more suggestive validator name than isISO8601
    • isISO8601 accepts also "only date string" inputs as 2019-04-04 - how can i use isDate() #407
    • we have missing strict option parameter in isISO8601
    • we should introduce isRFC3339 validator as RFC3339 is also date format standard - validatorjs
    • we should improve our docs
  10. ihorTymofieiev commented on Nov 14, 2019

    @ihorTymofieiev
    Contributor

    Merging #88 was a really not a good idea(

    Issues for isDateString:

    • "2019-18-13T22:14:14.761Z", because we can use any month in the range from 0 to 19
    • "2019-12-39T22:14:14.761Z", because we can use any day in the range from 0 to 39
    • "2019-12-31T29:14:14.761Z", because we can use any hour in the range from 0 to 29

    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 validatorjs/validator.js#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

  11. cjancsar commented on Dec 19, 2019

    @cjancsar
    Contributor

    @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,

  12. ihorTymofieiev commented on Jan 3, 2020

    @ihorTymofieiev
    Contributor

    @cjancsar, recent changes with fix this validator are not yet available as the npm package.

    @vlapo

  13. added a commit that references this issue on Aug 4, 2020
    40d64b9
  14. added
    status: fixed
    on Aug 4, 2020
  15. github-actions commented on Sep 4, 2020

    @github-actions

    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.

  16. locked as resolved and limited conversation to collaborators on Sep 4, 2020
  17. added
    status: done/released
    and removed
    status: fixed
    on Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: done/releasedtype: fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions