#[repr(transparent)]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
sourceimpl Time
impl Time
sourcepub const fn from_micros(micros: u64) -> Self
pub const fn from_micros(micros: u64) -> Self
Construct a new Time
from the specified number of microseconds.
sourcepub const fn from_millis(millis: u64) -> Self
pub const fn from_millis(millis: u64) -> Self
Construct a new Time
from the specified number of milliseconds.
Pancis if millis
overflows the representable range of Time
.
sourcepub const fn from_secs(secs: u64) -> Self
pub const fn from_secs(secs: u64) -> Self
Construct a new Time
from the specified number of seconds.
Pancis if secs
overflows the representable range of Time
.
sourcepub const fn as_micros(self) -> u64
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
.
sourcepub const fn as_millis(self) -> u64
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
.
sourcepub const fn as_secs(self) -> u64
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
.
sourcepub const fn as_secs_f64(self) -> f64
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);
sourcepub const fn as_secs_f32(self) -> f32
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);
sourcepub const fn core_duration_since_origin(self) -> Duration
pub const fn core_duration_since_origin(self) -> Duration
Get the duration since the origin as ::core::time::Duration
.
sourcepub const fn core_duration_since(self, reference: Self) -> Option<Duration>
pub const fn core_duration_since(self, reference: Self) -> Option<Duration>
Get the duration since the specified timestamp as
::core::time::Duration
. Returns None
if self
< reference
.
sourcepub const fn duration_since(self, reference: Self) -> Option<Duration>
pub const fn duration_since(self, reference: Self) -> Option<Duration>
Get the duration since the specified timestamp as Duration
. Returns
None
if the result overflows the representable range of Duration
.
sourcepub const fn wrapping_add(&self, duration: Duration) -> Self
pub const fn wrapping_add(&self, duration: Duration) -> Self
Advance the time by duration
and return the result.
sourcepub const fn wrapping_sub(&self, duration: Duration) -> Self
pub const fn wrapping_sub(&self, duration: Duration) -> Self
Put back the time by duration
and return the result.
Trait Implementations
sourceimpl AddAssign<Duration> for Time
impl AddAssign<Duration> for Time
sourcefn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
Advance the time by duration
in place.
sourceimpl Ord for Time
impl Ord for Time
sourceimpl PartialOrd<Time> for Time
impl PartialOrd<Time> for Time
sourcefn partial_cmp(&self, other: &Time) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
sourceimpl SubAssign<Duration> for Time
impl SubAssign<Duration> for Time
sourcefn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
Put back the time by duration
in place.
sourceimpl TryFrom<DateTime<Utc>> for Time
impl TryFrom<DateTime<Utc>> for Time
sourcefn try_from(value: DateTime<Utc>) -> Result<Self, Self::Error>
fn try_from(value: DateTime<Utc>) -> Result<Self, Self::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
type Error = TryFromDateTimeError
The type returned in the event of a conversion error.
sourceimpl TryFrom<Time> for DateTime<Utc>
impl TryFrom<Time> for DateTime<Utc>
sourcefn try_from(value: Time) -> Result<Self, Self::Error>
fn try_from(value: Time) -> Result<Self, Self::Error>
Try to construct a chrono_0p4::DateTime<chrono_0p4::Utc>
from the specified
Time
.
Returns an error if the specified Time
overflows the representable
range of the destination type.
Examples
use chrono_0p4::{DateTime, Utc, TimeZone};
use r3_core::time::Time;
assert_eq!(
DateTime::try_from(Time::from_micros(123_456_789)),
Ok(Utc.timestamp(123, 456_789_000)),
);
assert!(
DateTime::try_from(Time::from_micros(0xffff_ffff_ffff_ffff))
.is_err()
);
type Error = TryFromDateTimeError
type Error = TryFromDateTimeError
The type returned in the event of a conversion error.
impl Copy for Time
impl Eq for Time
impl StructuralEq for Time
impl StructuralPartialEq for Time
impl ZeroInit 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more