diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2020-09-16 15:57:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-16 15:57:13 +0000 |
commit | 12cbc4eadb53d44f93cee52c576f3cbfae11da57 (patch) | |
tree | 790871cdaeb87a71eaa21eb88137bab21f99dc11 /src/renderer.rs | |
parent | Merge pull request #376 from svenstaro/dependabot/cargo/chrono-humanize-0.1.1 (diff) | |
parent | Use Humanize for SystemTime directly (diff) | |
download | miniserve-12cbc4eadb53d44f93cee52c576f3cbfae11da57.tar.gz miniserve-12cbc4eadb53d44f93cee52c576f3cbfae11da57.zip |
Merge pull request #373 from KevCui/master
Show "now" when last modification time less than 11 seconds
Diffstat (limited to 'src/renderer.rs')
-rw-r--r-- | src/renderer.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index 17e0119..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::{Accuracy, HumanTime, Tense}; +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<SystemTime>) -> 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<SystemTime>) -> Option<String> { - 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)) +fn humanize_systemtime(time: Option<SystemTime>) -> Option<String> { + time.map(|time| time.humanize()) } /// Renders an error on the webpage |