mirror of
https://github.com/navidrome/navidrome.git
synced 2024-09-11 20:12:54 +02:00
30 lines
522 B
Go
30 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
|
|
}
|