mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
29 lines
522 B
Go
29 lines
522 B
Go
package log
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func ShortDur(d time.Duration) string {
|
|
var s string
|
|
switch {
|
|
case d > time.Hour:
|
|
s = d.Round(time.Minute).String()
|
|
case d > time.Minute:
|
|
s = d.Round(time.Second).String()
|
|
case d > time.Second:
|
|
s = d.Round(10 * time.Millisecond).String()
|
|
case d > time.Millisecond:
|
|
s = d.Round(100 * time.Microsecond).String()
|
|
default:
|
|
s = d.String()
|
|
}
|
|
if strings.HasSuffix(s, "m0s") {
|
|
s = s[:len(s)-2]
|
|
}
|
|
if strings.HasSuffix(s, "h0m") {
|
|
s = s[:len(s)-2]
|
|
}
|
|
return s
|
|
}
|