aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Cui <krazycavin@gmail.com>2020-09-16 10:07:51 +0000
committerKevin Cui <krazycavin@gmail.com>2020-09-16 10:07:51 +0000
commit74d966ea1639eb5cd0ca2f18215fbf5cee4d9ae7 (patch)
tree790871cdaeb87a71eaa21eb88137bab21f99dc11
parentMerge branch 'master' of github.com:svenstaro/miniserve (diff)
downloadminiserve-74d966ea1639eb5cd0ca2f18215fbf5cee4d9ae7.tar.gz
miniserve-74d966ea1639eb5cd0ca2f18215fbf5cee4d9ae7.zip
Use Humanize for SystemTime directly
Diffstat (limited to '')
-rw-r--r--src/renderer.rs12
1 files changed, 4 insertions, 8 deletions
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<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| format!("{}", HumanTime::from(-duration)))
+fn humanize_systemtime(time: Option<SystemTime>) -> Option<String> {
+ time.map(|time| time.humanize())
}
/// Renders an error on the webpage