Skip to content

Return error when a duration overflows, and update CI - #3

Merged
peterhellberg merged 3 commits into
masterfrom
fix-durationFunc-overflow
Nov 26, 2026
Merged

peterhellberg merged 3 commits into
masterfrom
fix-durationFunc-overflow

Conversation

@peterhellberg

@peterhellberg peterhellberg commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

durationFunc ignored errors from time.ParseDuration and returned 0, so a component too large for time.Duration was dropped without an error (e.g. P300Y returned (0, nil)). Components that fit on their own could also wrap around when added together, e.g. PT2000000H2000000H returned a negative duration.

Parse now returns ErrUnsupportedFormat in both cases. This follows #2, which did the same for components that fail strconv.ParseFloat.

Changes:

  • durationFunc returns an error instead of 0 when time.ParseDuration fails
  • durationFromMatchAndPrefix checks for overflow when adding components together
  • New TestParseOverflow covers overflowing components (positive and negative), overflowing totals, and the largest valid values (PT2562047H, -PT2562047H, P100Y)
  • Package doc comment reformatted with gofmt
  • CI:
    • test on Go 1.19.x (the go.mod minimum), 1.26.x and 1.27.x
    • bump actions/setup-go and actions/checkout to v7
    • run on pushes to master and on pull requests, to avoid duplicate runs

go vet, go test and go test -race pass locally on Go 1.27.4.

@peterhellberg peterhellberg self-assigned this Nov 26, 2026
@peterhellberg
peterhellberg merged commit 626d930 into master Nov 26, 2026
3 checks passed
@peterhellberg
peterhellberg deleted the fix-durationFunc-overflow branch November 26, 2026 07:38
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.

1 participant