From fc4840dc5da6222a37330898357eada47a6ee948 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 23 Apr 2024 03:15:37 +0200 Subject: [PATCH] feat(web): more human times --- web/src/components/mod.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/src/components/mod.rs b/web/src/components/mod.rs index 4de72b8..a8289cf 100644 --- a/web/src/components/mod.rs +++ b/web/src/components/mod.rs @@ -16,8 +16,19 @@ use leptos::*; pub fn DateTime(t: Option>) -> impl IntoView { match t { Some(t) => { - let pretty = t.format("%Y/%m/%d %H:%M:%S").to_string(); - let rfc = t.to_rfc3339(); + let delta = chrono::Utc::now() - t; + let pretty = if delta.num_seconds() < 60 { + format!("{}s ago", delta.num_seconds()) + } else if delta.num_minutes() < 60 { + format!("{}m ago", delta.num_minutes()) + } else if delta.num_hours() < 24 { + format!("{}h ago", delta.num_hours()) + } else if delta.num_days() < 90 { + format!("{}d ago", delta.num_days()) + } else { + t.format("%Y/%m/%d %H:%M:%S").to_string() + }; + let rfc = t.to_rfc2822(); Some(view! { {pretty} })