Skip to content

Commit a41a690

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

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/print/format.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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).expect("Invalid offset minutes");
534+
let date = offset
535+
.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)