Struct r3::time::Time

source ·
pub struct Time { /* private fields */ }
Expand description

Represents a timestamp used by the API surface of R3-OS.

The origin is application-defined. If an application desires to represent a calender time using Time, it’s recommended to use the midnight UTC on January 1, 1970 (a.k.a. “UNIX timestamp”) as the origin.

Time is backed by u64 and can represent up to 213,503,982 days with microsecond precision.

Implementations§

source§

impl Time

source

pub const ZERO: Time = Time{ micros: 0,}

Zero (the origin).

source

pub const MAX: Time = Time{ micros: u64::MAX,}

The large representable timestamp.

source

pub const fn from_micros(micros: u64) -> Time

Construct a new Time from the specified number of microseconds.

source

pub const fn from_millis(millis: u64) -> Time

Construct a new Time from the specified number of milliseconds.

Pancis if millis overflows the representable range of Time.

source

pub const fn from_secs(secs: u64) -> Time

Construct a new Time from the specified number of seconds.

Pancis if secs overflows the representable range of Time.

source

pub const fn as_micros(self) -> u64

Get the total number of whole microseconds contained in the time span between this Time and Self::ZERO.

source

pub const fn as_millis(self) -> u64

Get the total number of whole milliseconds contained in the time span between this Time and Self::ZERO.

source

pub const fn as_secs(self) -> u64

Get the total number of whole seconds contained in the time span between this Time and Self::ZERO.

source

pub const fn as_secs_f64(self) -> f64

Get the total number of seconds contained in the time span between this Time and Self::ZERO as f64.

Examples
use r3_core::time::Time;

let dur = Time::from_micros(1_201_250_000);
assert_eq!(dur.as_secs_f64(), 1201.25);
source

pub const fn as_secs_f32(self) -> f32

Get the total number of seconds contained in the time span between this Time and Self::ZERO as f32.

Examples
use r3_core::time::Time;

let dur = Time::from_micros(1_201_250_000);
assert_eq!(dur.as_secs_f32(), 1201.25);
source

pub const fn core_duration_since_origin(self) -> Duration

Get the duration since the origin as ::core::time::Duration.

source

pub const fn core_duration_since(self, reference: Time) -> Option<Duration>

Get the duration since the specified timestamp as ::core::time::Duration. Returns None if self < reference.

source

pub const fn duration_since(self, reference: Time) -> Option<Duration>

Get the duration since the specified timestamp as Duration. Returns None if the result overflows the representable range of Duration.

source

pub const fn wrapping_add(&self, duration: Duration) -> Time

Advance the time by duration and return the result.

source

pub const fn wrapping_sub(&self, duration: Duration) -> Time

Put back the time by duration and return the result.

Trait Implementations§

source§

impl Add<Duration> for Time

source§

fn add(self, rhs: Duration) -> <Time as Add<Duration>>::Output

Advance the time by duration and return the result.

§

type Output = Time

The resulting type after applying the + operator.
source§

impl AddAssign<Duration> for Time

source§

fn add_assign(&mut self, rhs: Duration)

Advance the time by duration in place.

source§

impl Clone for Time

source§

fn clone(&self) -> Time

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Time

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Time

source§

fn default() -> Time

Returns the “default value” for a type. Read more
source§

impl Hash for Time

source§

fn hash<__H>(&self, state: &mut __H)where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Init for Time

source§

const INIT: Time = Self::ZERO

The default value.
source§

impl Ord for Time

source§

fn cmp(&self, other: &Time) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Time> for Time

source§

fn eq(&self, other: &Time) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Time> for Time

source§

fn partial_cmp(&self, other: &Time) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<Duration> for Time

source§

fn sub(self, rhs: Duration) -> <Time as Sub<Duration>>::Output

Put back the time by duration and return the result.

§

type Output = Time

The resulting type after applying the - operator.
source§

impl SubAssign<Duration> for Time

source§

fn sub_assign(&mut self, rhs: Duration)

Put back the time by duration in place.

source§

impl TryFrom<DateTime<Utc>> for Time

source§

fn try_from( value: DateTime<Utc> ) -> Result<Time, <Time as TryFrom<DateTime<Utc>>>::Error>

Try to construct a Time from the specified chrono_0p4::DateTime<Utc>. Returns an error if the specified DateTime overflows the representable range of the destination type.

The sub-microsecond part is rounded by truncating.

Examples
use chrono_0p4::{DateTime, Utc, TimeZone};
use r3_core::time::Time;
assert_eq!(
    Time::try_from(Utc.timestamp(4, 123_456)),
    Ok(Time::from_micros(4_000_123)),
);
assert!(Time::try_from(Utc.timestamp(-1, 999_999_999)).is_err());
§

type Error = TryFromDateTimeError

The type returned in the event of a conversion error.
source§

impl Zeroable for Time

source§

fn zeroed() -> Self

source§

impl Copy for Time

source§

impl Eq for Time

source§

impl StructuralEq for Time

source§

impl StructuralPartialEq for Time

Auto Trait Implementations§

§

impl RefUnwindSafe for Time

§

impl Send for Time

§

impl Sync for Time

§

impl Unpin for Time

§

impl UnwindSafe for Time

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Id for Twhere T: Debug + Copy + Eq + Ord + Hash + Send + Sync + 'static + ?Sized,