pub struct UtcTimestamp(/* private fields */);Expand description
UTC timestamp with stable RFC 3339 serialization and a no_std epoch fallback.
now() reads the system clock with the std feature and returns Self::UNIX_EPOCH in a
no_std build, where no clock source is available.
§Examples
use omega_cognitive_kernel::UtcTimestamp;
let epoch = match UtcTimestamp::from_rfc3339("1970-01-01T00:00:00Z") {
Ok(epoch) => epoch,
Err(error) => panic!("valid RFC 3339 timestamp should parse: {error}"),
};
assert_eq!(epoch, UtcTimestamp::UNIX_EPOCH);
assert_eq!(epoch.timestamp(), 0);
assert_eq!(epoch.timestamp_millis(), 0);Implementations§
Source§impl UtcTimestamp
impl UtcTimestamp
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
Timestamp at the Unix epoch (1970-01-01T00:00:00Z).
Sourcepub fn to_rfc3339(&self) -> String
pub fn to_rfc3339(&self) -> String
Formats the timestamp as an RFC 3339 string.
Sourcepub fn from_rfc3339(s: &str) -> Result<Self, String>
pub fn from_rfc3339(s: &str) -> Result<Self, String>
Parses an RFC 3339 string and normalizes the result to UTC.
Sourcepub fn timestamp_millis(&self) -> i64
pub fn timestamp_millis(&self) -> i64
Returns whole milliseconds since the Unix epoch.
Trait Implementations§
Source§impl Clone for UtcTimestamp
impl Clone for UtcTimestamp
impl Copy for UtcTimestamp
Source§impl Debug for UtcTimestamp
impl Debug for UtcTimestamp
Source§impl Default for UtcTimestamp
impl Default for UtcTimestamp
Source§impl<'de> Deserialize<'de> for UtcTimestamp
impl<'de> Deserialize<'de> for UtcTimestamp
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for UtcTimestamp
impl Display for UtcTimestamp
impl Eq for UtcTimestamp
Source§impl Hash for UtcTimestamp
impl Hash for UtcTimestamp
Source§impl Ord for UtcTimestamp
impl Ord for UtcTimestamp
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for UtcTimestamp
impl PartialEq for UtcTimestamp
Source§impl PartialOrd for UtcTimestamp
impl PartialOrd for UtcTimestamp
Source§impl Serialize for UtcTimestamp
impl Serialize for UtcTimestamp
impl StructuralPartialEq for UtcTimestamp
Auto Trait Implementations§
impl Forget for UtcTimestamp
impl Freeze for UtcTimestamp
impl Move for UtcTimestamp
impl RefUnwindSafe for UtcTimestamp
impl Send for UtcTimestamp
impl Sync for UtcTimestamp
impl Unpin for UtcTimestamp
impl UnsafeUnpin for UtcTimestamp
impl UnwindSafe for UtcTimestamp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more