use std::fmt::Display;
use chrono::DateTime;
use serde::{Deserialize, Serialize};
#[allow(clippy::unsafe_derive_deserialize)]
#[derive(Debug, Default, Clone, Copy, Deserialize, Serialize)]
pub struct TimeStamp {
value: u64,
}
impl From<u64> for TimeStamp {
fn from(value: u64) -> Self {
Self { value }
}
}
impl Display for TimeStamp {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let date =
DateTime::from_timestamp(i64::try_from(self.value).expect("Should not wrap?"), 0)
.expect("This timestamp should be vaild");
let newdate = date.format("%Y-%m-%d %H:%M:%S");
f.write_str(newdate.to_string().as_str())
}
}
#[derive(Debug, Default, Clone, Copy, Ord, PartialOrd, Eq, PartialEq)]
pub struct UnsafeTimeStamp {
pub value: u64,
}
impl TimeStamp {
#[must_use]
pub unsafe fn to_unsafe(self) -> UnsafeTimeStamp {
UnsafeTimeStamp { value: self.value }
}
}