Struct hifitime::instant::Instant
[−]
[src]
pub struct Instant { /* fields omitted */ }
An Instant
type represents an instant with respect to 01 Jan 1900 at midnight, as per
the International Atomic Time (TAI) system.
Methods
impl Instant
[src]
pub fn new(seconds: u64, nanos: u32, era: Era) -> Instant
[src]
Creates a new Instant
with respect to TAI Epoch: 01 January 1900, 00:00:00.0.
All time systems are represented with respect to this epoch.
Note: this constructor relies on the constructor for std::time::Duration; as such,
refer to std::time::Duration::new
for pertinent warnings and limitations.
Examples
use hifitime::instant::{Era, Instant}; let epoch = Instant::new(0, 0, Era::Present); assert_eq!(epoch.secs(), 0); assert_eq!(epoch.nanos(), 0); let one_second_before_1900 = Instant::new(1, 0, Era::Past); assert_eq!(one_second_before_1900.secs(), 1); assert_eq!(one_second_before_1900.era(), Era::Past); let one_second_after_1900 = Instant::new(1, 0, Era::Present); assert_eq!(one_second_after_1900.secs(), 1); assert_eq!(one_second_after_1900.era(), Era::Present); assert!(one_second_after_1900 > epoch); assert!(one_second_after_1900 >= epoch); assert!(one_second_before_1900 < epoch); assert!(one_second_before_1900 <= epoch); assert!(Instant::new(1, 0, Era::Past) < Instant::new(0, 0, Era::Present)); assert!(Instant::new(1, 0, Era::Past) < Instant::new(1, 0, Era::Present)); // NOTE: Equality exists at epoch (or zero offset) assert_eq!(Instant::new(0, 0, Era::Past), Instant::new(0, 0, Era::Present)); assert_ne!(Instant::new(0, 1, Era::Past), Instant::new(0, 1, Era::Present)); assert_ne!(Instant::new(1, 1, Era::Past), Instant::new(1, 1, Era::Present)); assert_ne!(Instant::new(1, 0, Era::Past), Instant::new(1, 0, Era::Present));
pub fn from_precise_seconds(seconds: f64, era: Era) -> Instant
[src]
Creates a new Instant
from the number of seconds compared to Era
, provided as a floating point value.
Example
use hifitime::instant::{Era, Instant}; let example = Instant::new(159, 159, Era::Present); let in_secs = example.secs() as f64 + (example.nanos() as f64) * 1e-9; let precise = Instant::from_precise_seconds(in_secs, Era::Present); assert_eq!(precise, example); let example = Instant::new(159, 159, Era::Past); let in_secs = example.secs() as f64 + (example.nanos() as f64) * 1e-9; let precise = Instant::from_precise_seconds(in_secs, Era::Past); assert_eq!(precise, example);
pub fn duration(self) -> Duration
[src]
Returns the Duration with respect to Epoch (past OR present), check the era()
pub fn secs(self) -> u64
[src]
Returns the number of seconds with respect to the epoch.
pub fn nanos(self) -> u32
[src]
Returns the number of nanoseconds of the given instant.
pub fn era(self) -> Era
[src]
Returns the Era associated with this instant, i.e. whether it's before or after the TAI Epoch.
Trait Implementations
impl Clone for Instant
[src]
fn clone(&self) -> Instant
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Instant
[src]
impl Debug for Instant
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl PartialOrd for Instant
[src]
fn partial_cmp(&self, __arg_0: &Instant) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Instant) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Instant) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Instant) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Instant) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialEq for Instant
[src]
fn eq(&self, other: &Instant) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Add<Duration> for Instant
[src]
type Output = Instant
The resulting type after applying the +
operator.
fn add(self, delta: Duration) -> Instant
[src]
Adds a given std::time::Duration
to an Instant
.
Examples
use hifitime::instant::{Era, Instant, Duration}; // Add in the Present era. let tick = Instant::new(159, 10, Era::Present) + Duration::new(5, 2); assert_eq!(tick.secs(), 164); assert_eq!(tick.nanos(), 12); assert_eq!(tick.era(), Era::Present); // Add in the Past era. let tick = Instant::new(159, 10, Era::Past) + Duration::new(5, 2); assert_eq!(tick.secs(), 154); assert_eq!(tick.nanos(), 8); assert_eq!(tick.era(), Era::Past); // Add from the Past to overflow into the Present let tick = Instant::new(159, 0, Era::Past) + Duration::new(160, 0); assert_eq!(tick.secs(), 1); assert_eq!(tick.nanos(), 0); assert_eq!(tick.era(), Era::Present); let tick = Instant::new(0, 5, Era::Past) + Duration::new(0, 6); assert_eq!(tick.secs(), 0); assert_eq!(tick.nanos(), 1); assert_eq!(tick.era(), Era::Present);
impl Sub<Duration> for Instant
[src]
type Output = Instant
The resulting type after applying the -
operator.
fn sub(self, delta: Duration) -> Instant
[src]
Subtracts a given std::time::Duration
from an Instant
.
Examples
use hifitime::instant::{Era, Instant, Duration}; // Sub in the Present era. let tick = Instant::new(159, 10, Era::Present) - Duration::new(5, 2); assert_eq!(tick.secs(), 154); assert_eq!(tick.nanos(), 8); assert_eq!(tick.era(), Era::Present); // Sub in the Past era. let tick = Instant::new(159, 10, Era::Past) - Duration::new(5, 2); assert_eq!(tick.secs(), 164); assert_eq!(tick.nanos(), 12); assert_eq!(tick.era(), Era::Past); // Sub from the Present to overflow into the Past let tick = Instant::new(159, 0, Era::Present) - Duration::new(160, 0); assert_eq!(tick.secs(), 1); assert_eq!(tick.nanos(), 0); assert_eq!(tick.era(), Era::Past); let tick = Instant::new(0, 5, Era::Present) - Duration::new(0, 6); assert_eq!(tick.secs(), 0); assert_eq!(tick.nanos(), 1); assert_eq!(tick.era(), Era::Past);