8000 datetime validation fails if seconds are missing · Issue #3636 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000
datetime validation fails if seconds are missing #3636
Closed
@u2ix

Description

@u2ix

Have an issue with a valid datetime value, as produced by the browser in a datetime picker field, is not accepted by the datetime() validation. After some digging I figured that when the seconds :00 are added the validation passes.

But according to ISO 8601, just the hour is required for a valid time. Also as the timestamp is produced like this "2024-07-18T11:00", I feel it would be really great if this is accepted by the library as also the Date constructor doesn't have any issue with this.

For now I had to put in a quite ugly preprocess to make the validation pass on the value provided by the browser:

z.preprocess(input => `${input}:00`,
            z.string().datetime({ local: true }))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0