[][src]Struct lightning_invoice::PositiveTimestamp

pub struct PositiveTimestamp(_);

A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX timestamp is positive.

Invariants

The UNIX timestamp representing the stored time has to be positive and small enough so that a EpiryTime can be added to it without an overflow.

Methods

impl PositiveTimestamp
[src]

pub fn from_unix_timestamp(unix_seconds: u64) -> Result<Self, CreationError>
[src]

Create a new PositiveTimestamp from a unix timestamp in the Range 0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME, otherwise return a CreationError::TimestampOutOfBounds.

pub fn from_system_time(time: SystemTime) -> Result<Self, CreationError>
[src]

Create a new PositiveTimestamp from a SystemTime with a corresponding unix timestamp in the Range 0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME, otherwise return a CreationError::TimestampOutOfBounds.

pub fn as_unix_timestamp(&self) -> u64
[src]

Returns the UNIX timestamp representing the stored time

pub fn as_time(&self) -> &SystemTime
[src]

Returns a reference to the internal SystemTime time representation

Methods from Deref<Target = SystemTime>

pub const UNIX_EPOCH: SystemTime
1.28.0
[src]

pub fn duration_since(
    &self,
    earlier: SystemTime
) -> Result<Duration, SystemTimeError>
1.8.0
[src]

Returns the amount of time elapsed from an earlier point in time.

This function may fail because measurements taken earlier are not guaranteed to always be before later measurements (due to anomalies such as the system clock being adjusted either forwards or backwards).

If successful, Ok(Duration) is returned where the duration represents the amount of time elapsed from the specified measurement to this one.

Returns an Err if earlier is later than self, and the error contains how far from self the time is.

Examples

use std::time::SystemTime;

let sys_time = SystemTime::now();
let difference = sys_time.duration_since(sys_time)
                         .expect("SystemTime::duration_since failed");
println!("{:?}", difference);

pub fn elapsed(&self) -> Result<Duration, SystemTimeError>
1.8.0
[src]

Returns the amount of time elapsed since this system time was created.

This function may fail as the underlying system clock is susceptible to drift and updates (e.g., the system clock could go backwards), so this function may not always succeed. If successful, Ok(Duration) is returned where the duration represents the amount of time elapsed from this time measurement to the current time.

Returns an Err if self is later than the current system time, and the error contains how far from the current system time self is.

Examples

use std::thread::sleep;
use std::time::{Duration, SystemTime};

let sys_time = SystemTime::now();
let one_sec = Duration::from_secs(1);
sleep(one_sec);
assert!(sys_time.elapsed().unwrap() >= one_sec);

pub fn checked_add(&self, duration: Duration) -> Option<SystemTime>
[src]

🔬 This is a nightly-only experimental API. (time_checked_add)

Returns Some(t) where t is the time self + duration if t can be represented as SystemTime (which means it's inside the bounds of the underlying data structure), None otherwise.

pub fn checked_sub(&self, duration: Duration) -> Option<SystemTime>
[src]

🔬 This is a nightly-only experimental API. (time_checked_add)

Returns Some(t) where t is the time self - duration if t can be represented as SystemTime (which means it's inside the bounds of the underlying data structure), None otherwise.

Trait Implementations

impl Eq for PositiveTimestamp
[src]

impl Into<SystemTime> for PositiveTimestamp
[src]

impl PartialEq<PositiveTimestamp> for PositiveTimestamp
[src]

impl Clone for PositiveTimestamp
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for PositiveTimestamp
[src]

impl Deref for PositiveTimestamp
[src]

type Target = SystemTime

The resulting type after dereferencing.

impl FromBase32 for PositiveTimestamp
[src]

type Err = ParseError

The associated error which can be returned from parsing (e.g. because of bad padding).

impl ToBase32<Vec<u5>> for PositiveTimestamp
[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToBase32 for T where
    T: AsRef<[u8]>, 
[src]

fn to_base32(&self) -> Vec<u5>
[src]

Convert base256 to base32, adds padding if necessary