crabmail

Static HTML email archive viewer in Rust
git clone git://git.alexwennerberg.com/crabmail
Log | Files | Refs | README | LICENSE

commit 78d2c8188b6501f7a8ffde75e23869cef24a9e48
parent a8785af68de317c2b63895e5ef4a499887b708cf
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 12 Dec 2021 16:29:19 -0800

add solar year to timeago

Diffstat:
Mcrabmail/src/filters.rs | 7++++++-
Mcrabmail/src/main.rs | 1-
Dcrabmail/src/utils.rs | 1-
3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/crabmail/src/filters.rs b/crabmail/src/filters.rs @@ -5,6 +5,8 @@ pub fn time_ago(amount: &u64) -> askama::Result<String> { Ok(timeago(*amount)) } +const SOLAR_YEAR_SECS: u64 = 31556926; + fn timeago(unixtime: u64) -> String { let current_time = SystemTime::now() .duration_since(UNIX_EPOCH) @@ -25,9 +27,12 @@ fn timeago(unixtime: u64) -> String { } else if diff < 60 * 60 * 24 { amount = diff / (60 * 60); metric = "hour"; - } else { + } else if diff < SOLAR_YEAR_SECS * 2 { amount = diff / (60 * 60 * 24); metric = "day"; + } else { + amount = diff / SOLAR_YEAR_SECS * 2; + metric = "year"; } match amount { 1 => format!("{} {} ago", amount, metric), diff --git a/crabmail/src/main.rs b/crabmail/src/main.rs @@ -9,7 +9,6 @@ use std::io::prelude::*; use urlencoding::encode; mod filters; -mod utils; const HELP: &str = "\ Usage: crabmail diff --git a/crabmail/src/utils.rs b/crabmail/src/utils.rs @@ -1 +0,0 @@ -use std::time::{SystemTime, UNIX_EPOCH};