// always use the rule method
const rules = {
publish_at: [
rule('dateFormat', 'YYYY-MM-DD HH:mm:ss')
]
}
Ensures the date or date time is valid as the one of 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 on will result in different output, though the format is correct.
Timezone is only stripped when the date format expects timezone to be present.
Z
and ZZ
identifiers replaces their expected counter parts.
Also date can have Z
, which is equivalent to +00:00
.
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.
// always use the rule method
const rules = {
publish_at: [
rule('dateFormat', 'YYYY-MM-DD HH:mm:ss')
]
}
For customized build, you can import this rule as follows.
import { dateFormat } from 'indicative/builds/validations'