feature: enforce timezone info with isDateString
Description
Dates without timezone info are ambiguous (is it local time or UTC ? Only the caller knows). The ISO 8601 standard is great, but I want to ensure the presence of a timezone when validating my dates.
Proposed solution
I would like for isDateString (and IsDateString) to have an option "includeTimezone" (default to false) to ensure that a timezone is present in the string.
isDateString("2025-01-01 00:00:00", { includeTimezone: true }) // false
isDateString("2025-01-01 00:00:00Z", { includeTimezone: true }) // true
isDateString("2025-01-01 00:00:00+01:00", { includeTimezone: true }) // true
I understand that isDateString is an alias for isISO8601 from the package validator, maybe I should post this feature request to validator instead of here ?
Yes, you should post it there, since this would require a new validator. I think the answer is going to be no, since the general philosophy of that validator is to be roughly as permissive as the ISO standard is (which is very permissive since it allows ordinal dates which don't even look like dates if you're not used to them). ISO 8601 is far too permissive for a lot of people's use cases, in which case a RegeEx validator would probably be the better choice.