Format a duration in milliseconds to a human-readable string.
(ms: u64)
| 1232 | |
| 1233 | /// Format a duration in milliseconds to a human-readable string. |
| 1234 | fn format_duration_ms(ms: u64) -> String { |
| 1235 | let total_secs = ms / 1000; |
| 1236 | if total_secs >= 3600 { |
| 1237 | let hrs = total_secs / 3600; |
| 1238 | let mins = (total_secs % 3600) / 60; |
| 1239 | let secs = total_secs % 60; |
| 1240 | if secs > 0 { |
| 1241 | format!("{}h {}m {}s", hrs, mins, secs) |
| 1242 | } else { |
| 1243 | format!("{}h {}m", hrs, mins) |
| 1244 | } |
| 1245 | } else if total_secs >= 60 { |
| 1246 | let mins = total_secs / 60; |
| 1247 | let secs = total_secs % 60; |
| 1248 | if secs > 0 { |
| 1249 | format!("{}m {}s", mins, secs) |
| 1250 | } else { |
| 1251 | format!("{}m", mins) |
| 1252 | } |
| 1253 | } else if total_secs > 0 { |
| 1254 | format!("{}s", total_secs) |
| 1255 | } else { |
| 1256 | format!("{}ms", ms) |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | // Tests |
| 1261 |
no outgoing calls
no test coverage detected