Custom formatting of the age string, widen subject column.

This commit is contained in:
2023-11-20 17:41:58 -08:00
parent 95976c2860
commit f6c1835b18
4 changed files with 34 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ use std::{
hash::{Hash, Hasher},
};
use chrono::{DateTime, Datelike, Duration, Local, Utc};
use itertools::Itertools;
use log::{debug, error, info, Level};
use notmuch::{Content, Part, Thread, ThreadNode, ThreadSet};
@@ -481,6 +482,28 @@ fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
)
}
fn human_age(timestamp: i64) -> String {
let now = Local::now();
let ts = DateTime::<Utc>::from_timestamp(timestamp, 0)
.unwrap()
.with_timezone(&Local);
let age = now - ts;
let weekday = now.weekday();
let datetime = if age < Duration::minutes(1) {
format!("{} ago", age.num_seconds())
} else if age < Duration::hours(1) {
format!("{} ago", age.num_minutes())
} else if age < Duration::days(1) {
ts.format("%H:%M").to_string()
} else if age < Duration::weeks(1) {
ts.format("%a %H:%M").to_string()
} else {
ts.format("%b %e").to_string()
};
info!("dateime {datetime} TZ: {}", ts.offset());
datetime
}
fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult) -> Node<Msg> {
if query.is_empty() {
set_title("all mail");
@@ -503,6 +526,7 @@ fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult
]
*/
let tid = r.thread.clone();
let datetime = human_age(r.timestamp as i64);
div![
C!["row"],
div![
@@ -513,7 +537,7 @@ fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult
span![C!["from", "is-size-7"], pretty_authors(&r.authors)],
div![
span![C!["is-size-7"], tags_chiclet(&r.tags, true)],
span![C!["is-size-7", "float-right", "date"], &r.date_relative]
span![C!["is-size-7", "float-right", "date"], datetime]
]
]
});
@@ -536,6 +560,7 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No
let summaries = &search_results.summary.0;
let rows = summaries.iter().map(|r| {
let tid = r.thread.clone();
let datetime = human_age(r.timestamp as i64);
tr![
td![
C!["from"],
@@ -554,7 +579,7 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No
&r.subject,
]
],
td![C!["date"], &r.date_relative]
td![C!["date"], datetime]
]
});
let first = search_results.page * search_results.results_per_page;