You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

21 lines
578 B

package util
import (
"fmt"
"time"
)
func FormatDuration(d time.Duration) string {
if days := d / (time.Hour * 24); days > 0 {
hours := d % (time.Hour * 24) / time.Hour
return fmt.Sprintf("%d days %d hours", int(days), int(hours))
} else if hours := d / time.Hour; hours > 0 {
minutes := d % time.Hour / time.Minute
return fmt.Sprintf("%d hours %d minutes", int(hours), int(minutes))
} else {
minutes := d / time.Minute
seconds := d % time.Minute / time.Second
return fmt.Sprintf("%d minutes %d seconds", int(minutes), int(seconds))
}
return d.String()
}