use std::fmt::Display; use std::fmt::Formatter; use std::time::Duration; use std::time::SystemTime; use anyhow::Context; use chrono::offset::Utc; use chrono::DateTime; use chrono::TimeZone; use sequoia_openpgp as openpgp; use openpgp::types::Timestamp; /// The seconds in a day pub const SECONDS_IN_DAY : u64 = 24 * 60 * 60; /// The seconds in a year pub const SECONDS_IN_YEAR : u64 = // Average number of days in a year. (365.2422222 * SECONDS_IN_DAY as f64) as u64; use crate::Result; /// A signed offset (in seconds). #[derive(Debug, Clone, Eq, PartialEq)] pub struct Offset { /// Whether the offset is negative (strictly less than and not equal to 0). negative: bool, /// The number of seconds. seconds: u64, } /// A thin wrapper around `openpgp::types::Timestamp`. /// /// Recall: an OpenPGP timestamp has a whole second resolution, and /// uses a 32-bit quantity to represent the number of seconds since /// the UNIX epoch. #[derive(Debug, Clone, Eq, PartialEq)] pub enum Time { Timestamp(Timestamp), Offset(Offset), } impl std::str::FromStr for Time { type Err = anyhow::Error; fn from_str(s: &str) -> anyhow::Result