Skip to content

Conversation

@frenzzy
Copy link

@frenzzy frenzzy commented May 15, 2025

Fixes:

Changes:

  • Updated ISO 8601 timestamp regex to allow a single space before timezone offset (e.g., +00:00).

Reason:

  • PostgreSQL’s timestamptz default output includes a space before the timezone offset:
    SELECT NOW()::timestamptz;
    -- → '2025-05-13 14:15:41.123904 +00:00'
  • This aligns with the SQL standard output format, even though it’s not strictly ISO 8601 compliant.
  • The change improves compatibility with real PostgreSQL data and prevents false validation errors.

Copilot AI review requested due to automatic review settings May 15, 2025 09:30
@vercel
Copy link

vercel bot commented May 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
valibot ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 8:22pm

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the ISO 8601 timestamp regex to accept a single space before the timezone offset for better compatibility with PostgreSQL’s timestamptz output.

  • Allow an optional space before the UTC offset in ISO_TIMESTAMP_REGEX.
  • Add tests covering timestamps with a space before the offset.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
library/src/regex.ts Updated ISO_TIMESTAMP_REGEX to accept a leading space before +/- offset.
library/src/actions/isoTimestamp/isoTimestamp.test.ts Added a test suite for timestamps with a space before the UTC offset.

@fabian-hiller
Copy link
Member

Thank you for creating this PR! Are you aware of any drawbacks? I'm a bit concerned because it doesn't seem to be ISO 8601 compliant.

@fabian-hiller fabian-hiller self-assigned this May 16, 2025
@fabian-hiller fabian-hiller added the enhancement New feature or request label May 16, 2025
@frenzzy
Copy link
Author

frenzzy commented May 18, 2025

Thank you for asking! I agree this tweak isn’t strictly ISO 8601, but I don’t anticipate any serious drawbacks, mainly because it matches common real-world usage. For example, PostgreSQL’s timestamptz has for years output a space before the offset by default (following the SQL standard formatting). This means strings like "2025-05-13 14:15:41.123904 +00:00" are already out there – even modern JavaScript engines handle that format just fine (Date.parse() / new Date() don’t error on it in my testing).

Also, our current ISO_TIMESTAMP_REGEX isn’t a fully strict ISO 8601 validator anyway – we’ve already allowed a space instead of "T" between date and time, and the timezone offset was designed to be optional. In that light, permitting a leading space before the +/- offset is consistent with our pragmatic approach. It lets developers validate timestamps exactly as PostgreSQL emits them without having to pre-process the string or write a custom regex.

In short, this change improves compatibility with real data (avoiding false validation errors on perfectly valid SQL-standard timestamps) while staying aligned with the library’s goal of being practical and developer-friendly.

@fabian-hiller
Copy link
Member

Sorry for my late reply! I agree but I want to look at other schemas library like Zod first to see how they handle it. For now, I would plan to release this as a "fix" with Valibot v1.2.

@fabian-hiller fabian-hiller added this to the v1.2 milestone May 29, 2025
@frenzzy frenzzy force-pushed the iso-timestamp-offset-space branch from 4abb005 to c45337d Compare June 30, 2025 09:13
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 30, 2025
@frenzzy frenzzy force-pushed the iso-timestamp-offset-space branch from c45337d to 0e149f2 Compare July 28, 2025 20:19
@frenzzy frenzzy force-pushed the iso-timestamp-offset-space branch from 0e149f2 to 3fae6fa Compare November 25, 2025 15:17
@vercel
Copy link

vercel bot commented Nov 25, 2025

@frenzzy is attempting to deploy a commit to the Valibot Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants