mcfly/time.rs
1use chrono::{DateTime, Local, TimeZone};
2
3#[must_use]
4pub fn parse_timestamp(s: &str) -> i64 {
5 chrono_systemd_time::parse_timestamp_tz(s, Local)
6 .unwrap_or_else(|err| panic!("McFly error: Failed to parse timestamp ({err})"))
7 .latest()
8 .timestamp()
9}
10
11#[inline]
12#[must_use]
13pub fn to_datetime(timestamp: i64) -> String {
14 let utc = DateTime::from_timestamp(timestamp, 0).unwrap();
15 Local.from_utc_datetime(&utc.naive_utc()).to_rfc3339()
16}