FormatUptime formats the uptime in seconds to a human-readable format.
(uptime int)
| 18 | |
| 19 | // FormatUptime formats the uptime in seconds to a human-readable format. |
| 20 | func 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). |
no outgoing calls
no test coverage detected