feat(web): more human times

This commit is contained in:
əlemi 2024-04-23 03:15:37 +02:00
parent 5165aa6592
commit fc4840dc5d
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -16,8 +16,19 @@ use leptos::*;
pub fn DateTime(t: Option<chrono::DateTime<chrono::Utc>>) -> impl IntoView { pub fn DateTime(t: Option<chrono::DateTime<chrono::Utc>>) -> impl IntoView {
match t { match t {
Some(t) => { Some(t) => {
let pretty = t.format("%Y/%m/%d %H:%M:%S").to_string(); let delta = chrono::Utc::now() - t;
let rfc = t.to_rfc3339(); 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! { Some(view! {
<small title={rfc}>{pretty}</small> <small title={rfc}>{pretty}</small>
}) })