Files

38 lines
589 B
Go

package uptime
import (
"fmt"
"math"
)
type UptimeInformation struct {
Uptime float64
}
func (uptimeInfo UptimeInformation) FormatSeconds() string {
total := int64(math.Round(uptimeInfo.Uptime))
if total < 60 {
return fmt.Sprintf("%d", total)
}
s := total % 60
m := (total / 60) % 60
if total < 3600 {
// e.g., 5:03
return fmt.Sprintf("%d:%02d", m, s)
}
h := (total / 3600) % 24
if total < 86400 {
// e.g., 2:05:03
return fmt.Sprintf("%d:%02d:%02d", h, m, s)
}
d := total / 86400
// e.g., 1:02:05:03
return fmt.Sprintf("%d:%02d:%02d:%02d", d, h, m, s)
}