rsiot_messages_core/
timestamp.rs1use chrono::{DateTime, FixedOffset, Utc};
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
8pub struct Timestamp(pub DateTime<FixedOffset>);
9
10impl Timestamp {
11 pub fn format(&self, fmt: &str) -> String {
12 self.0.format(fmt).to_string()
13 }
14
15 pub fn to_rfc3339(&self) -> String {
17 self.0.to_rfc3339()
18 }
19
20 pub fn timestamp_nanos_opt(&self) -> Option<i64> {
21 self.0.timestamp_nanos_opt()
22 }
23}
24
25impl Default for Timestamp {
27 fn default() -> Self {
28 Self(Utc::now().into())
29 }
30}
31
32impl PartialOrd for Timestamp {
33 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
34 self.0.partial_cmp(&other.0)
35 }
36}