Using older version of Indicative or @adonisjs/validator?. Click here to access the old version documentation.

validations

dateFormat

Ensures the date or date time is valid as the per the defined formats.

This method will import format method from dateFns.

Note

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.

  1. Timezone is only stripped when the date format expects timezone to be present.

  2. Z and ZZ identifiers replaces their expected counter parts.

  3. Also date can have Z, which is equivalent to +00:00.

  4. If we will not strip the timezone offset from the actual date, then dateFns will format it in local timezone causing invalid date comparison.

  5. Validation will also fail, when format expects a timezone but missing in original date.