Skip to content

Commit

Permalink
output: shorten printed duration
Browse files Browse the repository at this point in the history
- truncate durations >=1 minute to 1 second precision,
- truncate durations >=1 second to 1 millisecond precision,
- limit precision to max. 1µs,
  • Loading branch information
fho committed Jun 21, 2024
1 parent 4e09220 commit 9563e59
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/command/term/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func FormatDuration(d time.Duration, opts ...FormatOption) string {
return fmt.Sprintf("%.3f", d.Seconds())
}

if d.Minutes() > 1 {
return d.Round(time.Second).String()
if d.Minutes() >= 1 {
return d.Truncate(time.Second).String()
}

if d.Milliseconds() > 1 {
return d.Round(time.Millisecond).String()
if d.Seconds() >= 1 {
return d.Truncate(time.Millisecond).String()
}

return d.String()
return d.Truncate(time.Microsecond).String()
}

0 comments on commit 9563e59

Please sign in to comment.