From 172c6699b81d47486980624b50c2bde26f28aca0 Mon Sep 17 00:00:00 2001 From: Kevin Cui Date: Sat, 12 Sep 2020 23:39:46 +0200 Subject: Show "now" when last modification time less than 11 seconds --- src/renderer.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/renderer.rs b/src/renderer.rs index 17e0119..5298f21 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -913,7 +913,13 @@ fn humanize_systemtime(src_time: Option) -> Option { src_time .and_then(|std_time| SystemTime::now().duration_since(std_time).ok()) .and_then(|from_now| Duration::from_std(from_now).ok()) - .map(|duration| HumanTime::from(duration).to_text_en(Accuracy::Rough, Tense::Past)) + .map(|duration| { + if duration < Duration::seconds(11) { + format!("now") + } else { + HumanTime::from(duration).to_text_en(Accuracy::Rough, Tense::Past) + } + }) } /// Renders an error on the webpage -- cgit v1.2.3 From 67fa9745a24f050e37a2ab2cbad24e821f4ff0cd Mon Sep 17 00:00:00 2001 From: Kevin Cui Date: Mon, 14 Sep 2020 14:05:47 +0200 Subject: Fix wrong use of format --- src/renderer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/renderer.rs b/src/renderer.rs index 5298f21..f39cc64 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -915,7 +915,7 @@ fn humanize_systemtime(src_time: Option) -> Option { .and_then(|from_now| Duration::from_std(from_now).ok()) .map(|duration| { if duration < Duration::seconds(11) { - format!("now") + "now".to_string() } else { HumanTime::from(duration).to_text_en(Accuracy::Rough, Tense::Past) } -- cgit v1.2.3 From 0fedd15a61d79735552137f9cb008a58f4554e20 Mon Sep 17 00:00:00 2001 From: Kevin Cui Date: Tue, 15 Sep 2020 21:11:43 +0200 Subject: Replace HumanTime::to_text_en by HumanTime --- src/renderer.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/renderer.rs b/src/renderer.rs index f39cc64..1192565 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,6 +1,6 @@ use actix_web::http::StatusCode; use chrono::{DateTime, Duration, Utc}; -use chrono_humanize::{Accuracy, HumanTime, Tense}; +use chrono_humanize::{HumanTime}; use maud::{html, Markup, PreEscaped, DOCTYPE}; use std::time::SystemTime; use strum::IntoEnumIterator; @@ -913,13 +913,7 @@ fn humanize_systemtime(src_time: Option) -> Option { src_time .and_then(|std_time| SystemTime::now().duration_since(std_time).ok()) .and_then(|from_now| Duration::from_std(from_now).ok()) - .map(|duration| { - if duration < Duration::seconds(11) { - "now".to_string() - } else { - HumanTime::from(duration).to_text_en(Accuracy::Rough, Tense::Past) - } - }) + .map(|duration| { format!("{}", HumanTime::from(-duration))}) } /// Renders an error on the webpage -- cgit v1.2.3 From e65c62fc568a8c052bd875e9a5ec168265f391ba Mon Sep 17 00:00:00 2001 From: Kevin Cui Date: Tue, 15 Sep 2020 21:14:54 +0200 Subject: Cleanup format --- src/renderer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/renderer.rs b/src/renderer.rs index 1192565..17d2baf 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -913,7 +913,7 @@ fn humanize_systemtime(src_time: Option) -> Option { src_time .and_then(|std_time| SystemTime::now().duration_since(std_time).ok()) .and_then(|from_now| Duration::from_std(from_now).ok()) - .map(|duration| { format!("{}", HumanTime::from(-duration))}) + .map(|duration| format!("{}", HumanTime::from(-duration))) } /// Renders an error on the webpage -- cgit v1.2.3 From 7e45f8c5f4295fb647d6221d243f75a68e984235 Mon Sep 17 00:00:00 2001 From: Kevin Cui Date: Tue, 15 Sep 2020 21:26:44 +0200 Subject: Fix cargo fmt check --- src/renderer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/renderer.rs b/src/renderer.rs index 17d2baf..b1e64be 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,6 +1,6 @@ use actix_web::http::StatusCode; use chrono::{DateTime, Duration, Utc}; -use chrono_humanize::{HumanTime}; +use chrono_humanize::HumanTime; use maud::{html, Markup, PreEscaped, DOCTYPE}; use std::time::SystemTime; use strum::IntoEnumIterator; -- cgit v1.2.3 From 74d966ea1639eb5cd0ca2f18215fbf5cee4d9ae7 Mon Sep 17 00:00:00 2001 From: Kevin Cui Date: Wed, 16 Sep 2020 12:07:51 +0200 Subject: Use Humanize for SystemTime directly --- src/renderer.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/renderer.rs b/src/renderer.rs index b1e64be..c26059e 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,6 +1,6 @@ use actix_web::http::StatusCode; -use chrono::{DateTime, Duration, Utc}; -use chrono_humanize::HumanTime; +use chrono::{DateTime, Utc}; +use chrono_humanize::Humanize; use maud::{html, Markup, PreEscaped, DOCTYPE}; use std::time::SystemTime; use strum::IntoEnumIterator; @@ -907,13 +907,9 @@ fn convert_to_utc(src_time: Option) -> Option<(String, String)> { } /// Converts a SystemTime to a string readable by a human, -/// i.e. calculates the duration between now() and the given SystemTime, /// and gives a rough approximation of the elapsed time since -fn humanize_systemtime(src_time: Option) -> Option { - src_time - .and_then(|std_time| SystemTime::now().duration_since(std_time).ok()) - .and_then(|from_now| Duration::from_std(from_now).ok()) - .map(|duration| format!("{}", HumanTime::from(-duration))) +fn humanize_systemtime(time: Option) -> Option { + time.map(|time| time.humanize()) } /// Renders an error on the webpage -- cgit v1.2.3