Skip to main content

TimeInstant

Trait TimeInstant 

Source
pub trait TimeInstant:
    Copy
    + Clone
    + PartialEq
    + PartialOrd
    + Sized {
    type Duration;

    // Required methods
    fn to_utc(&self) -> Option<DateTime<Utc>>;
    fn from_utc(datetime: DateTime<Utc>) -> Self;
    fn difference(&self, other: &Self) -> Self::Duration;
    fn add_duration(&self, duration: Self::Duration) -> Self;
    fn sub_duration(&self, duration: Self::Duration) -> Self;
}
Expand description

Trait for types that represent a point in time.

Types implementing this trait can be used as time instants in Interval<T> and provide conversions to/from UTC plus basic arithmetic operations.

Required Associated Types§

Source

type Duration

The duration type used for arithmetic operations.

Required Methods§

Source

fn to_utc(&self) -> Option<DateTime<Utc>>

Convert this time instant to UTC DateTime.

Source

fn from_utc(datetime: DateTime<Utc>) -> Self

Create a time instant from UTC DateTime.

Source

fn difference(&self, other: &Self) -> Self::Duration

Compute the difference between two time instants.

Source

fn add_duration(&self, duration: Self::Duration) -> Self

Add a duration to this time instant.

Source

fn sub_duration(&self, duration: Self::Duration) -> Self

Subtract a duration from this time instant.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TimeInstant for DateTime<Utc>

Source§

type Duration = TimeDelta

Source§

fn to_utc(&self) -> Option<DateTime<Utc>>

Source§

fn from_utc(datetime: DateTime<Utc>) -> Self

Source§

fn difference(&self, other: &Self) -> Self::Duration

Source§

fn add_duration(&self, duration: Self::Duration) -> Self

Source§

fn sub_duration(&self, duration: Self::Duration) -> Self

Implementors§