A better Rust ATProto crate

feat: expose timestamps directly on Datetime

authored by blooym.dev and committed by tangled.org a1e74672 d2e1257c

+29 -2
+29 -2
crates/jacquard-common/src/types/datetime.rs
··· 13 13 use crate::{CowStr, IntoStatic}; 14 14 #[cfg(all(not(target_arch = "wasm32"), feature = "std"))] 15 15 use regex::Regex; 16 + #[cfg(all(not(target_arch = "wasm32"), not(feature = "std")))] 17 + use regex_automata::meta::Regex; 16 18 #[cfg(target_arch = "wasm32")] 17 19 use regex_lite::Regex; 18 - #[cfg(all(not(target_arch = "wasm32"), not(feature = "std")))] 19 - use regex_automata::meta::Regex; 20 20 21 21 /// Regex for ISO 8601 datetime validation per AT Protocol spec 22 22 pub static ISO8601_REGEX: Lazy<Regex> = Lazy::new(|| { ··· 105 105 #[must_use] 106 106 pub fn as_str(&self) -> &str { 107 107 self.serialized.as_ref() 108 + } 109 + 110 + /// Extracts the number of non-leap seconds since January 1, 1970 0:00:00 UTC (aka "UNIX timestamp"). 111 + /// 112 + /// For full access to the underlying DateTime, use the [`AsRef<chrono::DateTime<chrono::FixedOffset>>`] implementation. 113 + #[inline] 114 + #[must_use] 115 + pub fn timestamp(&self) -> i64 { 116 + self.dt.timestamp() 117 + } 118 + 119 + /// Extracts the number of non-leap-milliseconds since January 1, 1970 UTC. 120 + /// 121 + /// For full access to the underlying DateTime, use the [`AsRef<chrono::DateTime<chrono::FixedOffset>>`] implementation. 122 + #[inline] 123 + #[must_use] 124 + pub fn timestamp_ms(&self) -> i64 { 125 + self.dt.timestamp_millis() 126 + } 127 + 128 + /// Extracts the number of non-leap-microseconds since January 1, 1970 UTC. 129 + /// 130 + /// For full access to the underlying DateTime, use the [`AsRef<chrono::DateTime<chrono::FixedOffset>>`] implementation. 131 + #[inline] 132 + #[must_use] 133 + pub fn timestamp_micros(&self) -> i64 { 134 + self.dt.timestamp_micros() 108 135 } 109 136 } 110 137