Skip to content

date-time accepts timestamps without "T" separator between date and time #55

Open
@jan-san

Description

According to the JSON Schema Validation spec, section 7.3.1 and ajv-formats' documentation, the date-time format should validate a string against the date-time production of RFC 3339, section 5.6.
This production requires the date and time components to be separated by "T" or "t".

The validation regex used in ajv-formats 2.1.1 however also accepts strings like "2023-01-22 11:11:11.123" with a whitespace character separating the date and time components (note the [t\s] portion):

/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i

This issue will be addressed in version 3. I am posting this issue for troubleshooting/documentation.

A workaround for ajv-formats 2.1.1 is to add a pattern() to the schema, e.g. using a slight variation of the regular expression used in ajv-formats 3:

S.string().format('date-time').pattern(/^\d\d\d\d-[0-1]\d-[0-3]\d[tT](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:[zZ]|[+-]\d\d(?::?\d\d)?)$/)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions