rsiot/message/
timestamp.rsuse chrono::{DateTime, FixedOffset, Timelike, Utc};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Timestamp(pub DateTime<FixedOffset>);
impl Timestamp {
pub fn format(&self, fmt: &str) -> String {
self.0.format(fmt).to_string()
}
pub fn to_rfc3339(&self) -> String {
self.0.to_rfc3339()
}
pub fn timestamp_nanos_opt(&self) -> Option<i64> {
self.0.timestamp_nanos_opt()
}
pub fn hour(&self) -> u32 {
self.0.hour()
}
pub fn minute(&self) -> u32 {
self.0.minute()
}
}
impl Default for Timestamp {
fn default() -> Self {
Self(Utc::now().into())
}
}
impl PartialOrd for Timestamp {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.0.partial_cmp(&other.0)
}
}