MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / FormatUptime

Function FormatUptime

internal/ui/utils/formatting.go:20–37  ·  view source on GitHub ↗

FormatUptime formats the uptime in seconds to a human-readable format.

(uptime int)

Source from the content-addressed store, hash-verified

18
19// FormatUptime formats the uptime in seconds to a human-readable format.
20func FormatUptime(uptime int) string {
21 if uptime <= 0 {
22 return "N/A"
23 }
24
25 duration := time.Duration(uptime) * time.Second
26 days := int(duration.Hours() / 24)
27 hours := int(duration.Hours()) % 24
28 minutes := int(duration.Minutes()) % 60
29
30 if days > 0 {
31 return fmt.Sprintf("%dd %dh %dm", days, hours, minutes)
32 }
33 if hours > 0 {
34 return fmt.Sprintf("%dh %dm", hours, minutes)
35 }
36 return fmt.Sprintf("%dm", minutes)
37}
38
39// FormatBytes formats a byte count to a human-readable format with dynamic units
40// Always shows 2 decimal places and chooses the most appropriate unit (GB, TB, PB).

Callers 3

UpdateMethod · 0.92
UpdateMethod · 0.92
populateTableMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected