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

Function relative_age

atomic-agent/src/hook_health.rs:608–622  ·  view source on GitHub ↗

Describe how long ago `then` was, relative to `now`, in coarse units.

(now: &str, then: &str)

Source from the content-addressed store, hash-verified

606
607/// Describe how long ago `then` was, relative to `now`, in coarse units.
608fn relative_age(now: &str, then: &str) -> String {
609 let (Ok(now), Ok(then)) = (
610 chrono::DateTime::parse_from_rfc3339(now),
611 chrono::DateTime::parse_from_rfc3339(then),
612 ) else {
613 return "recently".to_string();
614 };
615 let secs = (now - then).num_seconds().max(0);
616 match secs {
617 0..=59 => format!("{secs}s ago"),
618 60..=3599 => format!("{}m ago", secs / 60),
619 3600..=86_399 => format!("{}h ago", secs / 3600),
620 _ => format!("{}d ago", secs / 86_400),
621 }
622}
623
624#[cfg(test)]
625mod tests {

Callers 1

liveness_atMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected