Skip to content

Commit 0ab1ff8

Browse files
committed
fix chrono deprecations
1 parent 2274d7c commit 0ab1ff8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/components/utils/logitems.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use asyncgit::sync::{CommitId, CommitInfo};
2-
use chrono::{DateTime, Duration, Local, NaiveDateTime, Utc};
2+
use chrono::{DateTime, Duration, Local, Utc};
33
use indexmap::IndexSet;
44
use std::{rc::Rc, slice::Iter};
55

@@ -27,7 +27,8 @@ impl From<CommitInfo> for LogEntry {
2727
let hash_short = c.id.get_short_string().into();
2828

2929
let time = {
30-
let date = NaiveDateTime::from_timestamp_opt(c.time, 0);
30+
let date = DateTime::from_timestamp(c.time, 0)
31+
.map(|d| d.naive_utc());
3132
if date.is_none() {
3233
log::error!("error reading commit date: {hash_short} - timestamp: {}",c.time);
3334
}
@@ -61,8 +62,10 @@ impl From<CommitInfo> for LogEntry {
6162
impl LogEntry {
6263
pub fn time_to_string(&self, now: DateTime<Local>) -> String {
6364
let delta = now - self.time;
64-
if delta < Duration::minutes(30) {
65-
let delta_str = if delta < Duration::minutes(1) {
65+
if delta < Duration::try_minutes(30).unwrap_or_default() {
66+
let delta_str = if delta
67+
< Duration::try_minutes(1).unwrap_or_default()
68+
{
6669
"<1m ago".to_string()
6770
} else {
6871
format!("{:0>2}m ago", delta.num_minutes())

src/components/utils/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use chrono::{DateTime, Local, NaiveDateTime, Utc};
1+
use chrono::{DateTime, Local, Utc};
22
use unicode_width::UnicodeWidthStr;
33

44
#[cfg(feature = "ghemoji")]
@@ -30,8 +30,9 @@ macro_rules! try_or_popup {
3030
pub fn time_to_string(secs: i64, short: bool) -> String {
3131
let time = DateTime::<Local>::from(
3232
DateTime::<Utc>::from_naive_utc_and_offset(
33-
NaiveDateTime::from_timestamp_opt(secs, 0)
34-
.unwrap_or_default(),
33+
DateTime::from_timestamp(secs, 0)
34+
.unwrap_or_default()
35+
.naive_utc(),
3536
Utc,
3637
),
3738
);

0 commit comments

Comments
 (0)