From 45d850e8cafba28370b6468af52b1255ab45f680 Mon Sep 17 00:00:00 2001 From: extrawurst Date: Mon, 14 Nov 2022 14:06:43 +0100 Subject: [PATCH] fix new clippy warnings --- src/components/utils/logitems.rs | 17 ++++++++++++----- src/components/utils/mod.rs | 4 +++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/utils/logitems.rs b/src/components/utils/logitems.rs index 17a52e20..31c07bf0 100644 --- a/src/components/utils/logitems.rs +++ b/src/components/utils/logitems.rs @@ -22,11 +22,18 @@ pub struct LogEntry { impl From for LogEntry { fn from(c: CommitInfo) -> Self { - let time = + let hash_short = c.id.get_short_string().into(); + + let time = { + let date = NaiveDateTime::from_timestamp_opt(c.time, 0); + if date.is_none() { + log::error!("error reading commit date: {hash_short} - timestamp: {}",c.time); + } DateTime::::from(DateTime::::from_utc( - NaiveDateTime::from_timestamp(c.time, 0), + date.unwrap_or_default(), Utc, - )); + )) + }; let author = c.author; #[allow(unused_mut)] @@ -40,7 +47,7 @@ impl From for LogEntry { author: author.into(), msg: msg.into(), time, - hash_short: c.id.get_short_string().into(), + hash_short, id: c.id, } } @@ -56,7 +63,7 @@ impl LogEntry { format!("{:0>2}m ago", delta.num_minutes()) }; format!("{delta_str: <10}") - } else if self.time.date() == now.date() { + } else if self.time.date_naive() == now.date_naive() { self.time.format("%T ").to_string() } else { self.time.format("%Y-%m-%d").to_string() diff --git a/src/components/utils/mod.rs b/src/components/utils/mod.rs index ad5cb390..d003f958 100644 --- a/src/components/utils/mod.rs +++ b/src/components/utils/mod.rs @@ -26,9 +26,11 @@ macro_rules! try_or_popup { /// helper func to convert unix time since epoch to formated time string in local timezone pub fn time_to_string(secs: i64, short: bool) -> String { let time = DateTime::::from(DateTime::::from_utc( - NaiveDateTime::from_timestamp(secs, 0), + NaiveDateTime::from_timestamp_opt(secs, 0) + .unwrap_or_default(), Utc, )); + time.format(if short { "%Y-%m-%d" } else {