Open Toltar opened 2 years ago
Hmm, in my opinion, joi.isoDate()
scope is to only make sure that the date string conforms to ISO 8601 date time format. Value validation is the responsibility of javascript language or if you apply your own date-time value validation using library such as date-fns.
Without any other dependency, I believe that joi's value validation shouldn't be any different from javascript's implementation.
In this case, I think it wouldn't be this hard to compare an ISO string to what JavaScript gives back as ISO string once converted to Date. Thoughts @hueniverse?
Seems reasonable.
If this is implemented, I think it needs to be optional, something like Joi.date().iso().strict()
as the date constructor tolerates ISO strings with values that are out of range, but interprets them rationally as though they were the result of arithmetic without overflow.
e.g. ```
new Date('1973-11-31T21:33:09.000Z').toISOString() '1973-12-01T21:33:09.000Z'```
Context
What are you trying to achieve or the steps to reproduce?
I gave
isoDate()
an invalid date of2022-02-30T07:45:10.179Z
here, but errors is undefined.I know this seems kind of a niche bug, but I would think this would give an error at lease saying the user provided a ISO date that is simply just invalid. I notice in the code that we check if it is a valid date by checking if
getTime()
is NaN. But apparently, javascript just says that date is just March 1st of 2020.What was the result you got?
The iso date is valid for JOI even though there is no 30th of February.
What result did you expect?
I expected joi to catch this and give an error message saying that this is not a valid date at all.