MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / format_duration

Function format_duration

crates/opencode-util/src/util.rs:100–138  ·  view source on GitHub ↗
(secs: u64)

Source from the content-addressed store, hash-verified

98
99pub mod format {
100 pub fn format_duration(secs: u64) -> String {
101 if secs == 0 {
102 return String::new();
103 }
104 if secs < 60 {
105 return format!("{}s", secs);
106 }
107 if secs < 3600 {
108 let mins = secs / 60;
109 let remaining = secs % 60;
110 if remaining > 0 {
111 format!("{}m {}s", mins, remaining)
112 } else {
113 format!("{}m", mins)
114 }
115 } else if secs < 86400 {
116 let hours = secs / 3600;
117 let remaining = (secs % 3600) / 60;
118 if remaining > 0 {
119 format!("{}h {}m", hours, remaining)
120 } else {
121 format!("{}h", hours)
122 }
123 } else if secs < 604800 {
124 let days = secs / 86400;
125 if days == 1 {
126 "~1 day".to_string()
127 } else {
128 format!("~{} days", days)
129 }
130 } else {
131 let weeks = secs / 604800;
132 if weeks == 1 {
133 "~1 week".to_string()
134 } else {
135 format!("~{} weeks", weeks)
136 }
137 }
138 }
139
140 pub fn format_bytes(bytes: u64) -> String {
141 const KB: u64 = 1024;

Callers

nothing calls this directly

Calls 1

newFunction · 0.85

Tested by

no test coverage detected