Skip to content

Decode negative durations with ParseTime - #236

Merged
inhere merged 1 commit into
gookit:masterfrom
rupayon123:fix/config-contract-20261029
Oct 29, 2026
Merged

inhere merged 1 commit into
gookit:masterfrom
rupayon123:fix/config-contract-20261029

Conversation

@rupayon123

Copy link
Copy Markdown
Contributor

With ParseTime, decoding "-1s" into a duration field fails with an integer parsing error. The existing duration helper accepts it, but the decode hook only calls that helper for strings starting with a digit.

Try the same helper for negative values too. If it cannot parse one, leave it to the existing decoder so signed integer strings such as "-42" keep working. Environment-expanded duration values follow the same path.

Go 1.26.0 / macOS arm64 validation:

  • Ten regression cases fail before the fix; all 16 new cases pass afterward.
  • Full coverage and race runs each pass 212 leaf cases, with no skips or failures; statement coverage is 96.7%.
  • Vet, build, tidy, formatting and the YAML example pass. Staticcheck retains three baseline diagnostics; Revive reports the same 17 existing warnings.
  • Independent checks compare 144 actual decodes with the base: 16 intended improvements, 128 unchanged results, and no regressions. These include signed numeric formats, named types, zero values and overflow.

This preserves the existing duration grammar; it does not add +1s or .5s support. Hosted CI and other Go/OS combinations remain unverified locally.

@inhere
inhere merged commit 54bb633 into gookit:master Oct 29, 2026
12 checks passed
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.

2 participants