Skip to content

feat(isISO8601Duration): validate ISO 8601 durations - #2956

Open
Aschenbath wants to merge 1 commit into
validatorjs:masterfrom
Aschenbath:feat/iso8601-duration-2379
Open

Aschenbath wants to merge 1 commit into
validatorjs:masterfrom
Aschenbath:feat/iso8601-duration-2379

Conversation

@Aschenbath

Copy link
Copy Markdown

Add isISO8601Duration(str) so applications can validate media lengths and other ISO durations without supplying their own regular expression. The existing date-only isISO8601 behavior is unchanged.

Supports ordered year/month/day/time designators, standalone weeks, and alternative calendar/ordinal representations in basic or extended form, including date-only/time-only forms and reduced time precision. Fractions use a dot or comma and are restricted to the last represented unit. Alternative field limits follow ISO 8601:2004 section 4.4.3.3; ordinal days use the explicitly documented range 000 through 366 without leap-year checks. Signed durations, mixed weeks, expanded years and intervals are outside this API's documented scope.

Closes #2379.

References: ISO 8601:2004, sections 4.4.3.2 through 4.4.3.3 and their referenced date/time formats (4.1.2, 4.1.3, 4.2.2.2 through 4.2.2.5, 4.3.2 through 4.3.3). The alternative representation describes quantities rather than calendar dates, permits zero fields, and uses inclusive carry-over limits.

Validation: npm test passes all 333 tests, including every distribution build and ESLint. The 10 new groups fail on the exact base because the API is absent. Packed CommonJS, direct-module, browser, minified-browser and native ES-module consumption pass all 263 fixture inputs; Node 8 also passes the CommonJS/browser checks. Independent review passed 12,667 generated/boundary cases across four distributions (50,668 assertions). The direct new module also passes on Node 0.10; loading the complete package on that version encounters an existing Set dependency, reproduced on the exact base.

Implemented with OpenAI Codex and independently reviewed and tested by a separate Codex agent. No human code review is claimed.

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

@codecov

codecov Bot commented Nov 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ff3424) to head (853b075).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2956   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       115    +1     
  Lines         2599      2624   +25     
  Branches       658       667    +9     
=========================================
+ Hits          2599      2624   +25     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isISO8601 doesn't support duration

1 participant