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/renderer.rs') 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