Formate today and yesterday better.

This commit is contained in:
Bill Thiede 2023-11-20 17:53:49 -08:00
parent 6251c54873
commit 6901c9fde9

View File

@ -484,6 +484,7 @@ fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
fn human_age(timestamp: i64) -> String { fn human_age(timestamp: i64) -> String {
let now = Local::now(); let now = Local::now();
let yesterday = now - Duration::days(1);
let ts = DateTime::<Utc>::from_timestamp(timestamp, 0) let ts = DateTime::<Utc>::from_timestamp(timestamp, 0)
.unwrap() .unwrap()
.with_timezone(&Local); .with_timezone(&Local);
@ -493,8 +494,10 @@ fn human_age(timestamp: i64) -> String {
format!("{} min. ago", age.num_seconds()) format!("{} min. ago", age.num_seconds())
} else if age < Duration::hours(1) { } else if age < Duration::hours(1) {
format!("{} min. ago", age.num_minutes()) format!("{} min. ago", age.num_minutes())
} else if age < Duration::days(1) { } else if ts.date_naive() == now.date_naive() {
ts.format("%H:%M").to_string() ts.format("Today %H:%M").to_string()
} else if ts.date_naive() == yesterday.date_naive() {
ts.format("Yest. %H:%M").to_string()
} else if age < Duration::weeks(1) { } else if age < Duration::weeks(1) {
ts.format("%a %H:%M").to_string() ts.format("%a %H:%M").to_string()
} else { } else {