Format a duration in milliseconds to a human-readable string.
(ms: u64)
| 711 | |
| 712 | /// Format a duration in milliseconds to a human-readable string. |
| 713 | fn format_duration_ms(ms: u64) -> String { |
| 714 | let total_secs = ms / 1000; |
| 715 | if total_secs >= 3600 { |
| 716 | let hrs = total_secs / 3600; |
| 717 | let mins = (total_secs % 3600) / 60; |
| 718 | let secs = total_secs % 60; |
| 719 | if secs > 0 { |
| 720 | format!("{}h {}m {}s", hrs, mins, secs) |
| 721 | } else { |
| 722 | format!("{}h {}m", hrs, mins) |
| 723 | } |
| 724 | } else if total_secs >= 60 { |
| 725 | let mins = total_secs / 60; |
| 726 | let secs = total_secs % 60; |
| 727 | if secs > 0 { |
| 728 | format!("{}m {}s", mins, secs) |
| 729 | } else { |
| 730 | format!("{}m", mins) |
| 731 | } |
| 732 | } else if total_secs > 0 { |
| 733 | format!("{}s", total_secs) |
| 734 | } else { |
| 735 | format!("{}ms", ms) |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | // Tests |
| 740 |
no outgoing calls
no test coverage detected