Skip to content

Add types.Duration for the RFC 3339 duration format#144

Merged
mromaszewicz merged 1 commit into
mainfrom
fix/issue-66
Jul 12, 2026
Merged

Add types.Duration for the RFC 3339 duration format#144
mromaszewicz merged 1 commit into
mainfrom
fix/issue-66

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Closes: #66

The OpenAPI "duration" format references the RFC 3339 appendix A duration grammar, which the Go standard library does not implement, and the available third-party parsers are unmaintained or parse-only.

types.Duration stores the parsed components (years, months, weeks, days, hours, minutes, seconds), so any spec-valid duration round-trips losslessly through ParseDuration and String — calendar components have no fixed length in wall-clock time and cannot be represented by a time.Duration. The parser follows the RFC grammar strictly (component order and uniqueness, weeks exclusive, no negatives), with one documented interoperability deviation: fractional seconds are accepted (period or comma) and emitted when present.

TimeDuration and FromTimeDuration bridge to time.Duration where the conversion is well-defined: years and months error, weeks and days convert at the fixed 7-day/24-hour convention. JSON and text marshaling plus a Binder implementation make Duration a scalar binding target for parameters, like types.Date.

Closes: #66

The OpenAPI "duration" format references the RFC 3339 appendix A duration
grammar, which the Go standard library does not implement, and the
available third-party parsers are unmaintained or parse-only.

types.Duration stores the parsed components (years, months, weeks, days,
hours, minutes, seconds), so any spec-valid duration round-trips
losslessly through ParseDuration and String — calendar components have no
fixed length in wall-clock time and cannot be represented by a
time.Duration. The parser follows the RFC grammar strictly (component
order and uniqueness, weeks exclusive, no negatives), with one documented
interoperability deviation: fractional seconds are accepted (period or
comma) and emitted when present.

TimeDuration and FromTimeDuration bridge to time.Duration where the
conversion is well-defined: years and months error, weeks and days
convert at the fixed 7-day/24-hour convention. JSON and text marshaling
plus a Binder implementation make Duration a scalar binding target for
parameters, like types.Date.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mromaszewicz mromaszewicz requested a review from a team as a code owner July 12, 2026 22:47
@mromaszewicz mromaszewicz added the enhancement New feature or request label Jul 12, 2026
@mromaszewicz mromaszewicz merged commit e89dbb8 into main Jul 12, 2026
23 checks passed
@mromaszewicz mromaszewicz deleted the fix/issue-66 branch July 12, 2026 22:55
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.

Add support for RFC3339 durations

1 participant