Added uptime functionality

This commit is contained in:
lin committed 2026-10-05 22:12:10 +02:00
1 parent 403b621478
commit 6430e5ddca
5 files changed
+125 -2

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
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)
}