fix chrono deprecations

This commit is contained in:
extrawurst 2024-03-13 10:53:11 +01:00 committed by extrawurst
parent 2274d7c22f
commit 0ab1ff8625
2 changed files with 11 additions and 7 deletions

View File

@ -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())

View File

@ -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,
),
);