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

Zero (the origin).

The large representable timestamp.

Construct a new Time from the specified number of microseconds.

Construct a new Time from the specified number of milliseconds.

Pancis if millis overflows the representable range of Time.

Construct a new Time from the specified number of seconds.

Pancis if secs overflows the representable range of Time.

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

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

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

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);

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);

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

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

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

Advance the time by duration and return the result.

Put back the time by duration and return the result.

Trait Implementations

Advance the time by duration and return the result.

The resulting type after applying the + operator.

Advance the time by duration in place.

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The default value.
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Put back the time by duration and return the result.

The resulting type after applying the - operator.

Put back the time by duration in place.

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());
The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.