mod impl_timestamp;
mod impl_timestamp_repr;
#[allow(deprecated)]
mod impl_deprecated;
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(transparent)
)]
#[repr(transparent)]
pub struct Timestamp<T = u128>(pub T);
impl From<core::time::Duration> for Timestamp<u64> {
fn from(dur: core::time::Duration) -> Self {
Self(dur.as_secs())
}
}
impl From<core::time::Duration> for Timestamp<u128> {
fn from(dur: core::time::Duration) -> Self {
Self(dur.as_millis())
}
}
impl From<Timestamp<u64>> for core::time::Duration {
fn from(ts: Timestamp<u64>) -> Self {
Self::from_secs(*ts)
}
}
impl From<Timestamp<u128>> for core::time::Duration {
fn from(ts: Timestamp<u128>) -> Self {
Self::from_millis(*ts as u64)
}
}
#[cfg(feature = "chrono")]
impl<Tz> From<chrono::DateTime<Tz>> for Timestamp<i64>
where
Tz: chrono::TimeZone,
{
fn from(ts: chrono::DateTime<Tz>) -> Self {
Self(ts.timestamp())
}
}