42 lines
686 B
Go
42 lines
686 B
Go
package uptime
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
)
|
|
|
|
type UptimeInformation struct {
|
|
uptime float64
|
|
}
|
|
|
|
func (uptimeInfo UptimeInformation) GetUptime() (seconds float64) {
|
|
return uptimeInfo.uptime
|
|
}
|
|
|
|
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)
|
|
}
|