diff --git a/src/components/utils/logitems.rs b/src/components/utils/logitems.rs index 4534f225..67b9e56e 100644 --- a/src/components/utils/logitems.rs +++ b/src/components/utils/logitems.rs @@ -1,5 +1,5 @@ use asyncgit::sync::{CommitId, CommitInfo}; -use chrono::{DateTime, Duration, Local, NaiveDateTime, Utc}; +use chrono::{DateTime, Duration, Local, Utc}; use indexmap::IndexSet; use std::{rc::Rc, slice::Iter}; @@ -27,7 +27,8 @@ impl From for LogEntry { let hash_short = c.id.get_short_string().into(); let time = { - let date = NaiveDateTime::from_timestamp_opt(c.time, 0); + let date = DateTime::from_timestamp(c.time, 0) + .map(|d| d.naive_utc()); if date.is_none() { log::error!("error reading commit date: {hash_short} - timestamp: {}",c.time); } @@ -61,8 +62,10 @@ impl From for LogEntry { impl LogEntry { pub fn time_to_string(&self, now: DateTime) -> String { let delta = now - self.time; - if delta < Duration::minutes(30) { - let delta_str = if delta < Duration::minutes(1) { + if delta < Duration::try_minutes(30).unwrap_or_default() { + let delta_str = if delta + < Duration::try_minutes(1).unwrap_or_default() + { "<1m ago".to_string() } else { format!("{:0>2}m ago", delta.num_minutes()) diff --git a/src/components/utils/mod.rs b/src/components/utils/mod.rs index 54298d7a..29485be1 100644 --- a/src/components/utils/mod.rs +++ b/src/components/utils/mod.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, Local, NaiveDateTime, Utc}; +use chrono::{DateTime, Local, Utc}; use unicode_width::UnicodeWidthStr; #[cfg(feature = "ghemoji")] @@ -30,8 +30,9 @@ macro_rules! try_or_popup { pub fn time_to_string(secs: i64, short: bool) -> String { let time = DateTime::::from( DateTime::::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(secs, 0) - .unwrap_or_default(), + DateTime::from_timestamp(secs, 0) + .unwrap_or_default() + .naive_utc(), Utc, ), );