Time

Struct Time 

Source
pub struct Time(/* private fields */);
Expand description

A time value with nanosecond precision.

Implementations§

Source§

impl Time

Source

pub const MIN: Self

The minimum time value (1970-01-01T00:00:00.000000000Z).

Source

pub const MAX: Self

The maximum time value (2554-07-21T23:34:33.709551615Z).

Source

pub fn now() -> Self

Get the current system time.

§Panics

If the reported system time is less than Time::MIN or greater than Time::MAX.

Source

pub fn try_now() -> Result<Self, OutOfRange>

Get the current system time.

Fails if the reported system time is less than Time::MIN or greater than Time::MAX.

Source

pub fn coarse() -> Self

Get the current system time using CLOCK_REALTIME_COARSE.

This is faster but less precise than Time::now.

§Panics

If the reported system time is less than Time::MIN or greater than Time::MAX.

Source

pub fn try_coarse() -> Result<Self, OutOfRange>

Get the current system time using CLOCK_REALTIME_COARSE.

This is faster but less precise than Time::now.

Fails if the reported system time is less than Time::MIN or greater than Time::MAX.

Source

pub fn from_seconds(s: u64) -> Self

Construct a time value from the given seconds.

§Panics

If the given seconds are greater than Time::MAX seconds.

Source

pub fn try_from_seconds(s: u64) -> Result<Self, OutOfRange>

Construct a time value from the given seconds.

Fails if the given seconds are greater than Time::MAX seconds.

Source

pub const fn from_nanos(n: u64) -> Self

Construct a time value from the given nanoseconds.

Source

pub const fn seconds(self) -> u64

Seconds since the Unix epoch.

Source

pub const fn nanos(self) -> u64

Nanoseconds since the Unix epoch.

Source

pub const fn second_nanos(self) -> u64

Subsecond nanoseconds.

Source

pub fn try_add(self, t: Time) -> Result<Self, OutOfRange>

Try to add the given time value.

Fails if the result would be greater than Time::MAX.

Source

pub fn try_sub(self, t: Time) -> Result<Self, OutOfRange>

Try to substract the given time value.

Fails if the result would be less than Time::MIN.

Source

pub fn add_nanos(self, n: u64) -> Self

Add the given number of nanoseconds.

§Panics

If the result would be greater than Time::MAX. See Time::add_nanos_checked for an alternative that does not panic.

Source

pub fn add_seconds(self, s: u64) -> Self

Add the given number of seconds.

§Panics

If the result would be greater than Time::MAX. See Time::add_seconds_checked for an alternative that does not panic.

Source

pub fn add_minutes(self, m: u64) -> Self

Add the given number of minutes.

§Panics

If the result would be greater than Time::MAX. See Time::add_minutes_checked for an alternative that does not panic.

Source

pub fn add_hours(self, h: u64) -> Self

Add the given number of hours.

§Panics

If the result would be greater than Time::MAX. See Time::add_hours_checked for an alternative that does not panic.

Source

pub fn add_days(self, d: u64) -> Self

Add the given number of days.

§Panics

If the result would be greater than Time::MAX. See Time::add_days_checked for an alternative that does not panic.

Source

pub fn add_nanos_checked(self, n: u64) -> Result<Self, OutOfRange>

Add the given number of nanoseconds.

Fails if the result would be greater than Time::MAX.

Source

pub fn add_seconds_checked(self, s: u64) -> Result<Self, OutOfRange>

Add the given number of seconds.

Fails if the result would be greater than Time::MAX.

Source

pub fn add_minutes_checked(self, m: u64) -> Result<Self, OutOfRange>

Add the given number of minutes.

Fails if the result would be greater than Time::MAX.

Source

pub fn add_hours_checked(self, h: u64) -> Result<Self, OutOfRange>

Add the given number of hours.

Fails if the result would be greater than Time::MAX.

Source

pub fn add_days_checked(self, d: u64) -> Result<Self, OutOfRange>

Add the given number of days.

Fails if the result would be greater than Time::MAX.

Source

pub fn sub_nanos(self, n: u64) -> Self

Substract the given number of nanoseconds.

§Panics

If the result would be less than Time::MIN. See Time::sub_nanos_checked for an alternative that does not panic.

Source

pub fn sub_seconds(self, s: u64) -> Self

Substract the given number of seconds.

§Panics

If the result would be less than Time::MIN. See Time::sub_seconds_checked for an alternative that does not panic.

Source

pub fn sub_minutes(self, m: u64) -> Self

Substract the given number of minutes.

§Panics

If the result would be less than Time::MIN. See Time::sub_minutes_checked for an alternative that does not panic.

Source

pub fn sub_hours(self, h: u64) -> Self

Substract the given number of hours.

§Panics

If the result would be less than Time::MIN. See Time::sub_hours_checked for an alternative that does not panic.

Source

pub fn sub_days(self, d: u64) -> Self

Substract the given number of days.

§Panics

If the result would be less than Time::MIN. See Time::sub_days_checked for an alternative that does not panic.

Source

pub fn sub_nanos_checked(self, n: u64) -> Result<Self, OutOfRange>

Substract the given number of nanoseconds.

Fails if the result would be less than Time::MIN.

Source

pub fn sub_seconds_checked(self, s: u64) -> Result<Self, OutOfRange>

Substract the given number of seconds.

Fails if the result would be less than Time::MIN.

Source

pub fn sub_minutes_checked(self, m: u64) -> Result<Self, OutOfRange>

Substract the given number of minutes.

Fails if the result would be less than Time::MIN.

Source

pub fn sub_hours_checked(self, h: u64) -> Result<Self, OutOfRange>

Substract the given number of hours.

Fails if the result would be less than Time::MIN.

Source

pub fn sub_days_checked(self, d: u64) -> Result<Self, OutOfRange>

Substract the given number of days.

Fails if the result would be less than Time::MIN.

Source

pub const fn to_duration(self) -> Duration

Convert this time value to the std::time::Duration since the Unix epoch.

Source

pub fn duration_since(self, earlier: Self) -> Option<Duration>

Convert the delta between this time and the given one into a std::time::Duration.

Returns None if the argument is greater that self.

Source

pub fn as_u64(self) -> u64

Return this time value as a plain integer.

Source

pub fn to_utc_string(self) -> Option<String>

Format this time value as YYYY-MM-DDThh:mm:ss.nnnnnnnnnZ.

Requires feature "utc".

Trait Implementations§

Source§

impl Add<Duration> for Time

Source§

fn add(self, d: Duration) -> Self::Output

Adds the given duration.

§Panics

If the result would be greater than Time::MAX.

Source§

type Output = Time

The resulting type after applying the + operator.
Source§

impl Add for Time

Source§

fn add(self, t: Time) -> Self::Output

Adds the given time.

§Panics

If the result would be greater than Time::MAX.

Source§

type Output = Time

The resulting type after applying the + operator.
Source§

impl Clone for Time

Source§

fn clone(&self) -> Time

Returns a duplicate 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

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

impl<'bytes, Ctx> Decode<'bytes, Ctx> for Time

Source§

fn decode( __d777: &mut Decoder<'bytes>, __ctx777: &mut Ctx, ) -> Result<Time, Error>

Decode a value using the given Decoder. Read more
Source§

fn nil() -> Option<Self>

If possible, return a nil value of Self. Read more
Source§

impl<'de> Deserialize<'de> for Time

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Time

Source§

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

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

impl<Ctx> Encode<Ctx> for Time

Source§

fn encode<__W777>( &self, __e777: &mut Encoder<__W777>, __ctx777: &mut Ctx, ) -> Result<(), Error<__W777::Error>>
where __W777: Write,

Encode a value of this type using the given Encoder. Read more
Source§

fn is_nil(&self) -> bool

Is this value of Self a nil value? Read more
Source§

impl From<Time> for u64

Source§

fn from(value: Time) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Time

Source§

fn from(n: u64) -> Self

Converts to this type from the input type.
Source§

impl Hash for Time

Source§

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

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 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) -> Self
where Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for Time

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Time

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<Duration> for Time

Source§

fn sub(self, d: Duration) -> Self::Output

Subtracts the given duration.

§Panics

If the result would be less than Time::MIN.

Source§

type Output = Time

The resulting type after applying the - operator.
Source§

impl Sub for Time

Source§

fn sub(self, t: Time) -> Self::Output

Subtracts the given time.

§Panics

If the result would be less than Time::MIN.

Source§

type Output = Time

The resulting type after applying the - operator.
Source§

impl Copy for Time

Source§

impl Eq for Time

Source§

impl StructuralPartialEq for Time

Auto Trait Implementations§

§

impl Freeze for Time

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,