MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / format_age

Function format_age

crates/openshell-tui/src/lib.rs:2459–2481  ·  view source on GitHub ↗
(epoch_ms: i64)

Source from the content-addressed store, hash-verified

2457}
2458
2459fn format_age(epoch_ms: i64) -> String {
2460 if epoch_ms <= 0 {
2461 return String::from("-");
2462 }
2463 let created_secs = epoch_ms / 1000;
2464 let now = std::time::SystemTime::now()
2465 .duration_since(std::time::UNIX_EPOCH)
2466 .map_or(0, |d| d.as_secs().cast_signed());
2467 let diff = now - created_secs;
2468 if diff < 0 {
2469 return String::from("-");
2470 }
2471 let diff = diff.cast_unsigned();
2472 if diff < 60 {
2473 format!("{diff}s")
2474 } else if diff < 3600 {
2475 format!("{}m", diff / 60)
2476 } else if diff < 86400 {
2477 format!("{}h {}m", diff / 3600, (diff % 3600) / 60)
2478 } else {
2479 format!("{}d {}h", diff / 86400, (diff % 86400) / 3600)
2480 }
2481}
2482
2483/// Format epoch milliseconds as a human-readable UTC timestamp: `YYYY-MM-DD HH:MM`.
2484fn format_timestamp(epoch_ms: i64) -> String {

Callers 1

refresh_sandboxesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected