formatDuration formats a duration in a human-readable way.
(d time.Duration)
| 690 | |
| 691 | // formatDuration formats a duration in a human-readable way. |
| 692 | func formatDuration(d time.Duration) string { |
| 693 | if d == 0 { |
| 694 | return "0s" |
| 695 | } |
| 696 | |
| 697 | h := int(d.Hours()) |
| 698 | m := int(d.Minutes()) % 60 |
| 699 | s := int(d.Seconds()) % 60 |
| 700 | |
| 701 | if h > 0 { |
| 702 | return fmt.Sprintf("%dh%02dm%02ds", h, m, s) |
| 703 | } |
| 704 | if m > 0 { |
| 705 | return fmt.Sprintf("%dm%02ds", m, s) |
| 706 | } |
| 707 | return fmt.Sprintf("%ds", s) |
| 708 | } |
| 709 | |
| 710 | // wrapText wraps text to fit within a given width. |
| 711 | func wrapText(text string, width int) string { |
no outgoing calls
no test coverage detected