pub struct PositiveTimestamp(/* private fields */);
Expand description
A timestamp that refers to a date after 1 January 1970.
§Invariants
The Unix timestamp representing the stored time has to be positive and no greater than
MAX_TIMESTAMP
.
Implementations§
Source§impl PositiveTimestamp
impl PositiveTimestamp
Sourcepub fn from_unix_timestamp(unix_seconds: u64) -> Result<Self, CreationError>
pub fn from_unix_timestamp(unix_seconds: u64) -> Result<Self, CreationError>
Creates a PositiveTimestamp
from a Unix timestamp in the range 0..=MAX_TIMESTAMP
.
Otherwise, returns a CreationError::TimestampOutOfBounds
.
Sourcepub fn from_system_time(time: SystemTime) -> Result<Self, CreationError>
Available on crate feature std
only.
pub fn from_system_time(time: SystemTime) -> Result<Self, CreationError>
std
only.Creates a PositiveTimestamp
from a SystemTime
with a corresponding Unix timestamp in
the range 0..=MAX_TIMESTAMP
.
Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
Otherwise, returns a CreationError::TimestampOutOfBounds
.
Sourcepub fn from_duration_since_epoch(
duration: Duration,
) -> Result<Self, CreationError>
pub fn from_duration_since_epoch( duration: Duration, ) -> Result<Self, CreationError>
Creates a PositiveTimestamp
from a Duration
since the Unix epoch in the range
0..=MAX_TIMESTAMP
.
Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
Otherwise, returns a CreationError::TimestampOutOfBounds
.
Sourcepub fn as_unix_timestamp(&self) -> u64
pub fn as_unix_timestamp(&self) -> u64
Returns the Unix timestamp representing the stored time
Sourcepub fn as_duration_since_epoch(&self) -> Duration
pub fn as_duration_since_epoch(&self) -> Duration
Returns the duration of the stored time since the Unix epoch
Sourcepub fn as_time(&self) -> SystemTime
Available on crate feature std
only.
pub fn as_time(&self) -> SystemTime
std
only.Returns the SystemTime
representing the stored time
Trait Implementations§
Source§impl Clone for PositiveTimestamp
impl Clone for PositiveTimestamp
Source§fn clone(&self) -> PositiveTimestamp
fn clone(&self) -> PositiveTimestamp
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PositiveTimestamp
impl Debug for PositiveTimestamp
Source§impl From<PositiveTimestamp> for Duration
impl From<PositiveTimestamp> for Duration
Source§fn from(val: PositiveTimestamp) -> Self
fn from(val: PositiveTimestamp) -> Self
Source§impl From<PositiveTimestamp> for SystemTime
Available on crate feature std
only.
impl From<PositiveTimestamp> for SystemTime
std
only.