refactor(timeutil): unify duration formatters to eliminate minute-boundary artifacts - #55958
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Unifies duration formatting through FormatDuration, aligning CLI output and documentation.
Changes:
- Delegates millisecond and nanosecond formatting to the shared formatter.
- Updates boundary and CLI expectations.
- Revises public documentation.
Show a summary per file
| File | Description |
|---|---|
pkg/timeutil/format.go |
Consolidates formatter logic. |
pkg/timeutil/spec_test.go |
Updates public API expectations. |
pkg/timeutil/README.md |
Documents unified output. |
pkg/cli/token_usage_test.go |
Updates CLI duration tests. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
| {name: "just under minute rounds up in seconds range", inputMs: 59999, expected: "60.0s"}, | ||
| {name: "just under hour rounds to 60.0m", inputMs: 3599999, expected: "60.0m"}, |
There was a problem hiding this comment.
Fixed in 60cdd64: FormatDuration now rolls values into the next unit when rounding reaches the unit boundary (59999ms → "1.0m", 3599999ms → "1.0h"), and the spec/format/token_usage tests were updated to match.
| minutes := int(seconds) / 60 | ||
| secs := math.Mod(seconds, 60) | ||
| return fmt.Sprintf("%dm%.0fs", minutes, secs) | ||
| return FormatDuration(time.Duration(ms) * time.Millisecond) |
There was a problem hiding this comment.
Fixed in 60cdd64: FormatDurationMs now guards against overflow, formatting values above MaxInt64 / int64(time.Millisecond) directly in hours instead of converting to time.Duration.
|
Please do one focused follow-up pass:
Run: https://github.com/github/gh-aw/actions/runs/32943696113
|
…ters Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Pushed a follow-up pass (60cdd64) fixing the two outstanding review issues: boundary-rollover artifacts (59999ms → "1.0m", 3599999ms → "1.0h" instead of "60.0s"/"60.0m") and the int64 overflow guard in |
|
Triage update: Category: refactor | Risk: medium | Score: 48/100 (impact 20 + urgency 14 + quality 14) | Action: batch_review | Batch: workflow-runtime
|
|
Triage update: Category: refactor | Risk: medium | Score: 48/100 (impact 20 + urgency 14 + quality 14) | Action: batch_review | Batch: workflow-runtime
|
|
$ Please do one focused follow-up pass:
Run: https://github.com/github/gh-aw/actions/runs/32972030991
|
pkg/timeutilhad three diverging duration formatters, causing malformed boundary output (1m60s), missing hour rollover in ms formatting, and inconsistent rendering of equivalent durations across CLI surfaces. This change consolidates behavior around a single formatter path while preserving existing non-positive/short-ms edge behavior.Formatter unification
FormatDurationMsnow routes>=1000msthroughFormatDuration.FormatDurationNsnow routes positive values throughFormatDuration(still returns—for<=0).FormatDurationMs(<1000)remains millisecond-formatted (%dms) to preserve existing sub-second behavior.Behavior alignment at boundaries
1m60s.FormatDuration(including hour formatting).Spec/test/doc updates
pkg/timeutil/spec_test.goandpkg/cli/token_usage_test.goto match unified output style.59999,119999,3599999, and3600000ms.pkg/timeutil/README.mdexamples/ranges to reflect unified rendering.