Skip to content

add iso 8601 duration action - #1102

Open
muningis wants to merge 1 commit into
open-circle:mainfrom
muningis:iso_8601_duration
Open

add iso 8601 duration action#1102
muningis wants to merge 1 commit into
open-circle:mainfrom
muningis:iso_8601_duration

Conversation

@muningis

Copy link
Copy Markdown
Contributor

ISO8601 Duration (https://en.wikipedia.org/wiki/ISO_8601#Durations) - used (primarly) by string() schema

@vercel

vercel Bot commented Mar 23, 2025

Copy link
Copy Markdown

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 Mar 23, 2025 4:01pm

@fabian-hiller

Copy link
Copy Markdown
Member

Thank you very much! It may take me a while to review this PR as it is very important to me to check the validation closely. I hope to get back to you next week.

@muningis

Copy link
Copy Markdown
Contributor Author

Yeah, this one is quite biggish.

There's still also a question of whether 8601 (current), 8601-1 (allows to use Week designator with Year/Month/Day) or 8601-2 (allows +- before P, to determine if it's positive or negative value) should be supported.

@fabian-hiller

Copy link
Copy Markdown
Member

I will focus on reviewing and merging other actions first. If users want to see this PR merged, please give a 👍.

@fabian-hiller
fabian-hiller requested a review from Copilot April 20, 2025 00:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds support for ISO8601 durations by introducing a new action, issue, and corresponding type definitions along with documentation and tests.

  • Added new API routes in the documentation for isoDuration actions and issues
  • Created type definitions for IsoDurationIssue and IsoDurationAction in the API types folder
  • Implemented the isoDuration action, its validation function, and added comprehensive tests

Reviewed Changes

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

Show a summary per file
File Description
website/src/routes/api/menu.md Updated API menu with isoDuration and related entries
website/src/routes/api/(types)/IsoDurationIssue/properties.ts Added property definitions for IsoDurationIssue
website/src/routes/api/(types)/IsoDurationAction/properties.ts Added property definitions for IsoDurationAction
website/src/routes/api/(actions)/isoDuration/properties.ts Added property definitions for the isoDuration action
library/src/actions/isoDuration/isoDuration.ts Implemented the isoDuration action and overloads
library/src/actions/isoDuration/isoDuration.test.ts Provided tests covering valid and invalid ISO duration cases
library/src/actions/isoDuration/isoDuration.test-d.ts Added type tests for the isoDuration action
library/src/actions/isoDuration/isISO8601Duration.ts Implemented the validation function for ISO8601 durations
library/src/actions/isoDuration/index.ts Exported the isoDuration action
library/src/actions/index.ts Included exports for the new isoDuration action
Files not reviewed (8)
  • website/src/routes/api/(actions)/isoDuration/index.mdx: Language not supported
  • website/src/routes/api/(methods)/pipe/index.mdx: Language not supported
  • website/src/routes/api/(schemas)/any/index.mdx: Language not supported
  • website/src/routes/api/(schemas)/custom/index.mdx: Language not supported
  • website/src/routes/api/(schemas)/string/index.mdx: Language not supported
  • website/src/routes/api/(schemas)/unknown/index.mdx: Language not supported
  • website/src/routes/api/(types)/IsoDurationAction/index.mdx: Language not supported
  • website/src/routes/api/(types)/IsoDurationIssue/index.mdx: Language not supported

@pkg-pr-new

pkg-pr-new Bot commented Apr 20, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/valibot@1102

commit: 5d05997

@muningis

Copy link
Copy Markdown
Contributor Author

This schema is very niche, and I wouldn’t expect many people to need it. This is more of to have better compatibility with JSON Schemas.

with that in mind, this PR misses adjustments for to-json-schema package, so that this gets transformed to string’s format. Same for minEntries and maxEntries.

@fabian-hiller fabian-hiller added this to the v1.2 milestone Apr 22, 2025
@fabian-hiller

Copy link
Copy Markdown
Member

I will try to release it with Valibot v1.2

@yslpn yslpn self-assigned this Jul 26, 2026
@yslpn

yslpn commented Jul 26, 2026

Copy link
Copy Markdown
Member

@muningis Hi. Are you interested in refining this PR?

Hi. Are you interested in refining this PR?

I see you've created a complex function with 7 regexps ​​that thoroughly validates duration. This is quite verbose; our library is aimed at reducing bundle size and speed.

Could we use a more flexible and common validation, a single regular expression? Yes, it won't be as precise, but I think it's good enough.

https://github.com/ajv-validator/ajv-formats/blob/master/src/formats.ts#L54

Link #1497

And please fix conflicts

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants