Skip to content

feat: parse ISO 8601 durations#280

Closed
bernot-dev wants to merge 1 commit into
go-openapi:masterfrom
bernot-dev:iso8601-duration
Closed

feat: parse ISO 8601 durations#280
bernot-dev wants to merge 1 commit into
go-openapi:masterfrom
bernot-dev:iso8601-duration

Conversation

@bernot-dev

Copy link
Copy Markdown

Change type

🆕 New feature or enhancement

Short description

Support parsing ISO 8601 duration strings in ParseDuration.

Fixes

Full description

This change adds native support for parsing ISO 8601 durations within the ParseDuration function. It implements a dedicated, zero-allocation parser (ParseISO8601Duration in iso8601_duration.go) that handles all standard ISO 8601 duration designators (years, months, weeks, days, hours, minutes, and seconds), along with positive/negative signs and decimal fraction separators (supporting both dots and commas). By integrating this check into the main ParseDuration entry point, any incoming strings that begin with the P prefix (after trimming spaces and signs) are routed through the ISO 8601 parser. Comprehensive test suites have been introduced in iso8601_duration_test.go and duration_test.go to cover edge cases, validation rules, overflow boundaries, and format correctness.

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

Signed-off-by: Adam Bernot <bernot@google.com>
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.02%. Comparing base (7dcda43) to head (ac63017).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
iso8601_duration.go 97.39% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #280      +/-   ##
==========================================
+ Coverage   86.51%   87.02%   +0.50%     
==========================================
  Files          18       19       +1     
  Lines        2469     2589     +120     
==========================================
+ Hits         2136     2253     +117     
- Misses        230      232       +2     
- Partials      103      104       +1     

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

@fredbi fredbi mentioned this pull request Jul 14, 2026
@fredbi

fredbi commented Jul 14, 2026

Copy link
Copy Markdown
Member

Superseded by #284 . See also my comment to #278 . Thanks for the nudge: we needed that, but there is more to it than an extra parser.

@fredbi fredbi closed this Jul 14, 2026
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.

ISO 8601 Durations

2 participants