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

Function humanize_remaining

atomic-cli/src/commands/identity/agent/mod.rs:230–252  ·  view source on GitHub ↗

Render a duration as a short human phrase (`in 30d`, `3d ago`).

(remaining: Option<Duration>)

Source from the content-addressed store, hash-verified

228
229/// Render a duration as a short human phrase (`in 30d`, `3d ago`).
230pub fn humanize_remaining(remaining: Option<Duration>) -> String {
231 let Some(remaining) = remaining else {
232 return "never".to_string();
233 };
234 let days = remaining.num_days();
235 let hours = remaining.num_hours();
236
237 if remaining.num_seconds() < 0 {
238 let ago = -remaining;
239 return if ago.num_days() > 0 {
240 format!("{}d ago", ago.num_days())
241 } else {
242 format!("{}h ago", ago.num_hours().max(1))
243 };
244 }
245 if days > 0 {
246 format!("in {days}d")
247 } else if hours > 0 {
248 format!("in {hours}h")
249 } else {
250 "in <1h".to_string()
251 }
252}
253
254#[cfg(test)]
255mod tests {

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected