pub struct UnixTimestamp(/* private fields */);Expand description
A Unix timestamp representing seconds since the Unix epoch (1970-01-01T00:00:00Z).
This type is used throughout the x402 protocol for time-bounded payment authorizations:
validAfter: The earliest time a payment authorization can be executedvalidBefore: The latest time a payment authorization remains valid
§Serialization
Serialized as a stringified integer to avoid loss of precision in JSON, since
JavaScript’s Number type cannot safely represent all 64-bit integers.
"1699999999"§Example
use x402_types::timestamp::UnixTimestamp;
// Create a timestamp for "now"
let now = UnixTimestamp::now();
// Create a timestamp 1 hour in the future
let expires = now + 3600;
// Create from a specific value
let specific = UnixTimestamp::from_secs(1699999999);
assert_eq!(specific.as_secs(), 1699999999);Implementations§
Source§impl UnixTimestamp
impl UnixTimestamp
Sourcepub fn from_secs(secs: u64) -> Self
pub fn from_secs(secs: u64) -> Self
Creates a new UnixTimestamp from a raw seconds value.
§Example
use x402_types::timestamp::UnixTimestamp;
let ts = UnixTimestamp::from_secs(1699999999);
assert_eq!(ts.as_secs(), 1699999999);Sourcepub fn now() -> Self
pub fn now() -> Self
Returns the current system time as a UnixTimestamp.
§Panics
Panics if the system clock is set to a time before the Unix epoch, which should never happen on properly configured systems.
§Example
use x402_types::timestamp::UnixTimestamp;
let now = UnixTimestamp::now();
// Timestamp should be after year 2020
assert!(now.as_secs() > 1577836800);Trait Implementations§
Source§impl Add<u64> for UnixTimestamp
impl Add<u64> for UnixTimestamp
Source§impl Clone for UnixTimestamp
impl Clone for UnixTimestamp
Source§fn clone(&self) -> UnixTimestamp
fn clone(&self) -> UnixTimestamp
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UnixTimestamp
impl Debug for UnixTimestamp
Source§impl<'de> Deserialize<'de> for UnixTimestamp
impl<'de> Deserialize<'de> for UnixTimestamp
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 UnixTimestamp
impl Display for UnixTimestamp
Source§impl Ord for UnixTimestamp
impl Ord for UnixTimestamp
Source§fn cmp(&self, other: &UnixTimestamp) -> Ordering
fn cmp(&self, other: &UnixTimestamp) -> Ordering
1.21.0 · 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
Source§impl PartialEq for UnixTimestamp
impl PartialEq for UnixTimestamp
Source§impl PartialOrd for UnixTimestamp
impl PartialOrd for UnixTimestamp
Source§impl Serialize for UnixTimestamp
impl Serialize for UnixTimestamp
impl Copy for UnixTimestamp
impl Eq for UnixTimestamp
impl StructuralPartialEq for UnixTimestamp
Auto Trait Implementations§
impl Freeze for UnixTimestamp
impl RefUnwindSafe for UnixTimestamp
impl Send for UnixTimestamp
impl Sync for UnixTimestamp
impl Unpin for UnixTimestamp
impl UnwindSafe for UnixTimestamp
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