Commit

Author:

Hash:

Timestamp:

+7 -1 +/-1 browse

Kevin Schoon [me@kevinschoon.com]

a526b28d4e7b8d1348459704be862adcc6316f67

Tue, 13 May 2025 17:23:48 +0000 (6 months ago)

show more precision when displaying modifications older than one year
1diff --git a/crates/timeutil/src/lib.rs b/crates/timeutil/src/lib.rs
2index 4208580..164afc4 100644
3--- a/crates/timeutil/src/lib.rs
4+++ b/crates/timeutil/src/lib.rs
5 @@ -47,7 +47,13 @@ pub fn friendly(seconds: u64) -> String {
6 pluralize(seconds / MONTH),
7 )
8 } else {
9- message = format!("{} year{} ago", seconds / YEAR, pluralize(seconds / YEAR),)
10+ // show more precision when displaying modifications older than one year
11+ let as_float = (seconds as f64) / (YEAR as f64);
12+ message = format!(
13+ "{:.1} year{} ago",
14+ as_float,
15+ pluralize(if as_float > 1.0 { 0 } else { 1 })
16+ )
17 }
18 message
19 }