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

Function format_duration_ms

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

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

(ms: u64)

Source from the content-addressed store, hash-verified

711
712/// Format a duration in milliseconds to a human-readable string.
713fn 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

Callers 2

api_duration_displayMethod · 0.85
wall_duration_displayMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected