validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

isISO8601 returns true for an invalid iso8601 date

Open maxywk opened this issue 2 years ago • 13 comments

Describe the bug When using isISO8601 to check date that looks like iso8601 format, but missing seconds, will return true even though it is an invalid date

Examples Date string such as "2018-09-11T10:16.000Z" will return true. Live sample: https://codesandbox.io/s/wandering-fire-qr6fm6?file=/src/index.js

Additional context Validator.js version: 13.7.0 Node.js version: 16 OS platform: macOS

maxywk avatar Jul 18 '22 15:07 maxywk

@rubiin Can I work on this issue?

sahilsuman933 avatar Jul 24 '22 07:07 sahilsuman933

@sahilsuman933 sure jump ahead. Before you do, read the contribution guidelines though

rubiin avatar Jul 24 '22 14:07 rubiin

@rubiin Sure.

sahilsuman933 avatar Jul 24 '22 15:07 sahilsuman933

@rubiin I was validating the test cases for the iso8601, and many of them are incorrectly placed.

For example, 2009-222 is not a valid ISO8601 date but is put in the validISO8601.

Also, there is no need for isValidDate function cause there we can already use the inbuilt !isNaN(Date.parse) method to validate whether it is a valid date. One more thing, I think there is no need for a strict separator.

So I was thinking of re-writing the whole new ISO8601 code. So can I go ahead and do it?

sahilsuman933 avatar Jul 26 '22 19:07 sahilsuman933

Sure. As long as the tests are properly written and the logic defines the code

rubiin avatar Jul 27 '22 01:07 rubiin