A better Rust ATProto crate

feat: expose timestamps directly on Datetime #6

closed opened by blooym.dev targeting main from [deleted fork]: timestamps-on-datetime
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:p5yjdr64h7mk5l3kh6oszryk/sh.tangled.repo.pull/3md2ik6zlp422
+29 -2
Diff #0
+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_millis(&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

History

1 round 2 comments
sign up or login to add to the discussion
blooym.dev submitted #0
2 commits
expand
4769a7e3
feat: expose timestamps directly on Datetime
d1f65423
chore: align naming from chrono
expand 2 comments

Yeah, this is a good addition. I should probably also add that doc comment about AsRef further up. sorry for taking a while to get round to this.

note, i did merge this. rebasing some of my own local commits to accommodate seems to have confused tangled

closed without merging