MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / format_duration_ms

Function format_duration_ms

atomic-core/src/change/attestation.rs:1234–1258  ·  view source on GitHub ↗

Format a duration in milliseconds to a human-readable string.

(ms: u64)

Source from the content-addressed store, hash-verified

1232
1233/// Format a duration in milliseconds to a human-readable string.
1234fn 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

Callers 2

api_duration_displayMethod · 0.85
wall_duration_displayMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected