1
0
mirror of https://github.com/nxshock/gwp.git synced 2024-11-27 03:31:02 +05:00
gwp/durationformat.go

47 lines
704 B
Go
Raw Normal View History

2022-01-08 18:40:23 +05:00
package gwp
import (
"fmt"
"time"
)
func fmtDuration(d time.Duration) string {
d = d.Round(time.Second)
days := d / time.Hour / 24
d -= days * 24 * time.Hour
hours := d / time.Hour
d -= hours * time.Hour
minites := d / time.Minute
d -= minites * time.Minute
seconds := d / time.Second
d -= seconds * time.Second
var resultStr string
if days > 0 {
resultStr += fmt.Sprintf("%3dd", days)
} else {
resultStr += " "
}
if hours > 0 {
resultStr += fmt.Sprintf(" %2dh", hours)
} else {
resultStr += " "
}
if minites > 0 {
resultStr += fmt.Sprintf(" %2dm", minites)
} else {
resultStr += " "
}
resultStr += fmt.Sprintf(" %2ds", seconds)
return resultStr
}