Skip to content

refactor(timeutil): unify duration formatters to eliminate minute-boundary artifacts - #55958

Merged
pelikhan merged 5 commits into
mainfrom
copilot/refactor-pkg-timeutil-duration-formatters
Aug 26, 2026
Merged

refactor(timeutil): unify duration formatters to eliminate minute-boundary artifacts#55958
pelikhan merged 5 commits into
mainfrom
copilot/refactor-pkg-timeutil-duration-formatters

Conversation

Copilot AI commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

pkg/timeutil had 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

    • FormatDurationMs now routes >=1000ms through FormatDuration.
    • FormatDurationNs now routes positive values through FormatDuration (still returns for <=0).
    • FormatDurationMs(<1000) remains millisecond-formatted (%dms) to preserve existing sub-second behavior.
  • Behavior alignment at boundaries

    • Removes independent min/sec arithmetic that produced artifacts like 1m60s.
    • Inherits consistent rollover semantics from FormatDuration (including hour formatting).
  • Spec/test/doc updates

    • Updated expectations in pkg/timeutil/spec_test.go and pkg/cli/token_usage_test.go to match unified output style.
    • Added explicit boundary coverage for 59999, 119999, 3599999, and 3600000 ms.
    • Updated pkg/timeutil/README.md examples/ranges to reflect unified rendering.
func FormatDurationMs(ms int) string {
	if ms < 1000 {
		return fmt.Sprintf("%dms", ms)
	}
	return FormatDuration(time.Duration(ms) * time.Millisecond)
}

func FormatDurationNs(ns int64) string {
	if ns <= 0 {
		return "—"
	}
	return FormatDuration(time.Duration(ns))
}

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 18 AIC · ⌖ 8.17 AIC · ⊞ 8.7K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 26, 2026 06:37
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duration formatters in pkg/timeutil refactor(timeutil): unify duration formatters to eliminate minute-boundary artifacts Aug 26, 2026
Copilot AI requested a review from pelikhan August 26, 2026 06:42
@pelikhan
pelikhan marked this pull request as ready for review August 26, 2026 06:56
Copilot AI balanced review requested due to automatic review settings August 26, 2026 06:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread pkg/timeutil/spec_test.go Outdated
Comment on lines +69 to +70
{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"},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/timeutil/format.go
minutes := int(seconds) / 60
secs := math.Mod(seconds, 60)
return fmt.Sprintf("%dm%.0fs", minutes, secs)
return FormatDuration(time.Duration(ms) * time.Millisecond)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 60cdd64: FormatDurationMs now guards against overflow, formatting values above MaxInt64 / int64(time.Millisecond) directly in hours instead of converting to time.Duration.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

gh-aw-pr-sous-chef
@copilot PR Sous Chef triage: this PR still needs a forward-progress pass before maintainer investigation is likely to be productive.

Please do one focused follow-up pass:

  • refresh the branch if needed and use the pr-finisher skill before handing back for review

Run: https://github.com/github/gh-aw/actions/runs/32943696113

Generated by 👨🍳 PR Sous Chef

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 18 AIC · ⌖ 8.17 AIC · ⊞ 8.7K ·
Comment /souschef to run again

…ters

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

gh-aw-pr-sous-chef
@copilot PR Sous Chef triage: this PR still needs a forward-progress pass before maintainer investigation is likely to be productive.
...

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 FormatDurationMs for very large millisecond values. Also updated the stale test expectations that were pulled in from main via the merge, and addressed follow-up code_review feedback (32-bit int truncation risk in the new test, magic-number cleanup).

@github-actions

Copy link
Copy Markdown
Contributor

Triage update: Category: refactor | Risk: medium | Score: 48/100 (impact 20 + urgency 14 + quality 14) | Action: batch_review | Batch: workflow-runtime

Generated by 🔧 PR Triage Agent · copilot · mai10 · 17.1 AIC · ⌖ 2.78 AIC · ⊞ 15.6K ·

@github-actions

Copy link
Copy Markdown
Contributor

Triage update: Category: refactor | Risk: medium | Score: 48/100 (impact 20 + urgency 14 + quality 14) | Action: batch_review | Batch: workflow-runtime

Generated by 🔧 PR Triage Agent · copilot · mai10 · 17.1 AIC · ⌖ 2.78 AIC · ⊞ 15.6K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

$gh-aw-pr-sous-chef
@copilot PR Sous Chef triage: this PR still needs a forward-progress pass before maintainer investigation is likely to be productive.

Please do one focused follow-up pass:

  • refresh the branch if needed and use the pr-finisher skill before handing back for review

Run: https://github.com/github/gh-aw/actions/runs/32972030991

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 5.54 AIC · ⌖ 8.13 AIC · ⊞ 6.3K ·
Comment /souschef to run again

@pelikhan
pelikhan merged commit b35086e into main Aug 26, 2026
2 of 3 checks passed
@pelikhan
pelikhan deleted the copilot/refactor-pkg-timeutil-duration-formatters branch August 26, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] pkg/timeutil: three duration formatters diverge, one emits "1m60s"

4 participants