Ensures the date or date time is valid as the per the defined formats.
This method will import format method from dateFns.
Following steps are performed to strip the timezone from the actual date and then format the date. Keeping timezones will result in different output, even when the format is correct.
Timezone is only stripped when the date format expects timezone to be present.
ZZidentifiers replaces their expected counter parts.
Also date can have
Z, which is equivalent to
If we will not strip the timezone offset from the actual date, then dateFns will format it in local timezone causing invalid date comparison.
Validation will also fail, when format expects a timezone but missing in original date.