diff options
author | extrawurst <mail@rusticorn.com> | 2024-03-13 10:53:11 +0100 |
---|---|---|
committer | extrawurst <776816+extrawurst@users.noreply.github.com> | 2024-03-13 11:00:31 +0100 |
commit | 0ab1ff862592d5a16785306d64c035db24e87380 (patch) | |
tree | 5a4c41b215c6819767cc49243c903723dc0787ae /src | |
parent | 2274d7c22fa8956a6e7db13d4c614a7704c199d7 (diff) |
fix chrono deprecations
Diffstat (limited to 'src')
-rw-r--r-- | src/components/utils/logitems.rs | 11 | ||||
-rw-r--r-- | src/components/utils/mod.rs | 7 |
2 files changed, 11 insertions, 7 deletions
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<CommitInfo> 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<CommitInfo> for LogEntry { impl LogEntry { pub fn time_to_string(&self, now: DateTime<Local>) -> 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::<Local>::from( DateTime::<Utc>::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, ), ); |