Type Alias chrono::Duration

source ·
pub type Duration = TimeDelta;
Expand description

Alias of TimeDelta.

Aliased Type§

struct Duration {
    secs: i64,
    nanos: i32,
}

Fields§

§secs: i64§nanos: i32

Implementations§

source§

impl TimeDelta

source

pub const fn new(secs: i64, nanos: u32) -> Option<TimeDelta>

Makes a new TimeDelta with given number of seconds and nanoseconds.

Errors

Returns None when the duration is out of bounds, or if nanos ≥ 1,000,000,000.

source

pub const fn weeks(weeks: i64) -> TimeDelta

Makes a new TimeDelta with the given number of weeks.

Equivalent to TimeDelta::seconds(weeks * 7 * 24 * 60 * 60) with overflow checks.

Panics

Panics when the duration is out of bounds.

source

pub const fn try_weeks(weeks: i64) -> Option<TimeDelta>

Makes a new TimeDelta with the given number of weeks.

Equivalent to TimeDelta::try_seconds(weeks * 7 * 24 * 60 * 60) with overflow checks.

Errors

Returns None when the TimeDelta would be out of bounds.

source

pub const fn days(days: i64) -> TimeDelta

Makes a new TimeDelta with the given number of days.

Equivalent to TimeDelta::seconds(days * 24 * 60 * 60) with overflow checks.

Panics

Panics when the TimeDelta would be out of bounds.

source

pub const fn try_days(days: i64) -> Option<TimeDelta>

Makes a new TimeDelta with the given number of days.

Equivalent to TimeDelta::try_seconds(days * 24 * 60 * 60) with overflow checks.

Errors

Returns None when the TimeDelta would be out of bounds.

source

pub const fn hours(hours: i64) -> TimeDelta

Makes a new TimeDelta with the given number of hours.

Equivalent to TimeDelta::seconds(hours * 60 * 60) with overflow checks.

Panics

Panics when the TimeDelta would be out of bounds.

source

pub const fn try_hours(hours: i64) -> Option<TimeDelta>

Makes a new TimeDelta with the given number of hours.

Equivalent to TimeDelta::try_seconds(hours * 60 * 60) with overflow checks.

Errors

Returns None when the TimeDelta would be out of bounds.

source

pub const fn minutes(minutes: i64) -> TimeDelta

Makes a new TimeDelta with the given number of minutes.

Equivalent to TimeDelta::seconds(minutes * 60) with overflow checks.

Panics

Panics when the TimeDelta would be out of bounds.

source

pub const fn try_minutes(minutes: i64) -> Option<TimeDelta>

Makes a new TimeDelta with the given number of minutes.

Equivalent to TimeDelta::try_seconds(minutes * 60) with overflow checks.

Errors

Returns None when the TimeDelta would be out of bounds.

source

pub const fn seconds(seconds: i64) -> TimeDelta

Makes a new TimeDelta with the given number of seconds.

Panics

Panics when seconds is more than i64::MAX / 1_000 or less than -i64::MAX / 1_000 (in this context, this is the same as i64::MIN / 1_000 due to rounding).

source

pub const fn try_seconds(seconds: i64) -> Option<TimeDelta>

Makes a new TimeDelta with the given number of seconds.

Errors

Returns None when seconds is more than i64::MAX / 1_000 or less than -i64::MAX / 1_000 (in this context, this is the same as i64::MIN / 1_000 due to rounding).

source

pub const fn milliseconds(milliseconds: i64) -> TimeDelta

Makes a new TimeDelta with the given number of milliseconds.

Panics

Panics when the TimeDelta would be out of bounds, i.e. when milliseconds is more than i64::MAX or less than -i64::MAX. Notably, this is not the same as i64::MIN.

source

pub const fn try_milliseconds(milliseconds: i64) -> Option<TimeDelta>

Makes a new TimeDelta with the given number of milliseconds.

Errors

Returns None the TimeDelta would be out of bounds, i.e. when milliseconds is more than i64::MAX or less than -i64::MAX. Notably, this is not the same as i64::MIN.

source

pub const fn microseconds(microseconds: i64) -> TimeDelta

Makes a new TimeDelta with the given number of microseconds.

The number of microseconds acceptable by this constructor is less than the total number that can actually be stored in a TimeDelta, so it is not possible to specify a value that would be out of bounds. This function is therefore infallible.

source

pub const fn nanoseconds(nanos: i64) -> TimeDelta

Makes a new TimeDelta with the given number of nanoseconds.

The number of nanoseconds acceptable by this constructor is less than the total number that can actually be stored in a TimeDelta, so it is not possible to specify a value that would be out of bounds. This function is therefore infallible.

source

pub const fn num_weeks(&self) -> i64

Returns the total number of whole weeks in the TimeDelta.

source

pub const fn num_days(&self) -> i64

Returns the total number of whole days in the TimeDelta.

source

pub const fn num_hours(&self) -> i64

Returns the total number of whole hours in the TimeDelta.

source

pub const fn num_minutes(&self) -> i64

Returns the total number of whole minutes in the TimeDelta.

source

pub const fn num_seconds(&self) -> i64

Returns the total number of whole seconds in the TimeDelta.

source

pub const fn subsec_nanos(&self) -> i32

Returns the number of nanoseconds such that subsec_nanos() + num_seconds() * NANOS_PER_SEC is the total number of nanoseconds in the TimeDelta.

source

pub const fn num_milliseconds(&self) -> i64

Returns the total number of whole milliseconds in the TimeDelta.

source

pub const fn num_microseconds(&self) -> Option<i64>

Returns the total number of whole microseconds in the TimeDelta, or None on overflow (exceeding 2^63 microseconds in either direction).

source

pub const fn num_nanoseconds(&self) -> Option<i64>

Returns the total number of whole nanoseconds in the TimeDelta, or None on overflow (exceeding 2^63 nanoseconds in either direction).

source

pub const fn checked_add(&self, rhs: &TimeDelta) -> Option<TimeDelta>

Add two TimeDeltas, returning None if overflow occurred.

source

pub const fn checked_sub(&self, rhs: &TimeDelta) -> Option<TimeDelta>

Subtract two TimeDeltas, returning None if overflow occurred.

source

pub const fn checked_mul(&self, rhs: i32) -> Option<TimeDelta>

Multiply a TimeDelta with a i32, returning None if overflow occurred.

source

pub const fn checked_div(&self, rhs: i32) -> Option<TimeDelta>

Divide a TimeDelta with a i32, returning None if dividing by 0.

source

pub const fn abs(&self) -> TimeDelta

Returns the TimeDelta as an absolute (non-negative) value.

source

pub const fn min_value() -> TimeDelta

The minimum possible TimeDelta: -i64::MAX milliseconds.

source

pub const fn max_value() -> TimeDelta

The maximum possible TimeDelta: i64::MAX milliseconds.

source

pub const fn zero() -> TimeDelta

A TimeDelta where the stored seconds and nanoseconds are equal to zero.

source

pub const fn is_zero(&self) -> bool

Returns true if the TimeDelta equals TimeDelta::zero().

source

pub const fn from_std(duration: Duration) -> Result<TimeDelta, OutOfRangeError>

Creates a TimeDelta object from std::time::Duration

This function errors when original duration is larger than the maximum value supported for this type.

source

pub const fn to_std(&self) -> Result<Duration, OutOfRangeError>

Creates a std::time::Duration object from a TimeDelta.

This function errors when duration is less than zero. As standard library implementation is limited to non-negative values.

source

pub(crate) const fn neg(self) -> TimeDelta

This duplicates Neg::neg because trait methods can’t be const yet.

Trait Implementations§

source§

impl Add<TimeDelta> for TimeDelta

§

type Output = TimeDelta

The resulting type after applying the + operator.
source§

fn add(self, rhs: TimeDelta) -> TimeDelta

Performs the + operation. Read more
source§

impl AddAssign<TimeDelta> for TimeDelta

source§

fn add_assign(&mut self, rhs: TimeDelta)

Performs the += operation. Read more
source§

impl Clone for TimeDelta

source§

fn clone(&self) -> TimeDelta

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 TimeDelta

source§

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

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

impl Default for TimeDelta

source§

fn default() -> TimeDelta

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

impl Display for TimeDelta

source§

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

Format a TimeDelta using the ISO 8601 format

source§

impl Div<i32> for TimeDelta

§

type Output = TimeDelta

The resulting type after applying the / operator.
source§

fn div(self, rhs: i32) -> TimeDelta

Performs the / operation. Read more
source§

impl Hash for TimeDelta

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 Mul<i32> for TimeDelta

§

type Output = TimeDelta

The resulting type after applying the * operator.
source§

fn mul(self, rhs: i32) -> TimeDelta

Performs the * operation. Read more
source§

impl Neg for TimeDelta

§

type Output = TimeDelta

The resulting type after applying the - operator.
source§

fn neg(self) -> TimeDelta

Performs the unary - operation. Read more
source§

impl Ord for TimeDelta

source§

fn cmp(&self, other: &TimeDelta) -> 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<TimeDelta> for TimeDelta

source§

fn eq(&self, other: &TimeDelta) -> 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<TimeDelta> for TimeDelta

source§

fn partial_cmp(&self, other: &TimeDelta) -> 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<TimeDelta> for TimeDelta

§

type Output = TimeDelta

The resulting type after applying the - operator.
source§

fn sub(self, rhs: TimeDelta) -> TimeDelta

Performs the - operation. Read more
source§

impl SubAssign<TimeDelta> for TimeDelta

source§

fn sub_assign(&mut self, rhs: TimeDelta)

Performs the -= operation. Read more
source§

impl<'a> Sum<&'a TimeDelta> for TimeDelta

source§

fn sum<I: Iterator<Item = &'a TimeDelta>>(iter: I) -> TimeDelta

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl Sum<TimeDelta> for TimeDelta

source§

fn sum<I: Iterator<Item = TimeDelta>>(iter: I) -> TimeDelta

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl Copy for TimeDelta

source§

impl Eq for TimeDelta

source§

impl StructuralEq for TimeDelta

source§

impl StructuralPartialEq for TimeDelta