Skip to content

Commit 13dc1fa

Browse files
committed
Avoid deprecated function chrono::Local::timestamp()
1 parent a330f4a commit 13dc1fa

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/print/format.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Formatting of commits.
22
3-
use chrono::{FixedOffset, Local, TimeZone};
3+
use chrono::{FixedOffset, TimeZone};
44
use git2::{Commit, Time};
55
use lazy_static::lazy_static;
66
use std::fmt::Write;
@@ -530,9 +530,12 @@ pub fn format(
530530
}
531531

532532
pub fn format_date(time: Time, format: &str) -> String {
533-
let date =
534-
Local::from_offset(&FixedOffset::east(time.offset_minutes())).timestamp(time.seconds(), 0);
535-
format!("{}", date.format(format))
533+
let offset = FixedOffset::east_opt(time.offset_minutes() * 60)
534+
.expect("Invalid offset minutes");
535+
let date = offset.timestamp_opt(time.seconds(), 0)
536+
.single()
537+
.expect("Invalid timestamp, maybe a fold or gap in local time");
538+
date.format(format).to_string()
536539
}
537540

538541
/// Format a time as a relative time string (e.g., "21 hours ago", "4 days ago")

0 commit comments

Comments
 (0)