zod icon indicating copy to clipboard operation
zod copied to clipboard

Datetime validation with offset should allow all variants from ISO-8601

Open rafw87 opened this issue 3 years ago • 0 comments

Currently datetime validator allows only offset in format [+-]hh:mm, but ISO-8601 defines also [+-]hhmm or [+-]hh.

z.string().datetime({offset: true}).parse("2022-01-01T00:00:00+01:00") // success
z.string().datetime({offset: true}).parse("2022-01-01T00:00:00+0100") / error
z.string().datetime({offset: true}).parse("2022-01-01T00:00:00+01") error

Current pattern fragment for offset:

(([+-]\\d{2}:\\d{2})|Z)

Proposed:

(([+-]\\d{2}(:?\\d{2})?)|Z)

rafw87 avatar Dec 15 '22 12:12 rafw87