chrono

Type Alias Duration

Source
pub type Duration = TimeDelta;
Expand description

Alias of TimeDelta.

Aliased Type§

struct Duration { /* private fields */ }

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.

Trait Implementations

Source§

impl Add for TimeDelta

Source§

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 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§

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

Source§

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§

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

Source§

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

Source§

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§

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

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

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

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

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

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

impl PartialEq for TimeDelta

Source§

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

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

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 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§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

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§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

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 Sub for TimeDelta

Source§

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

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for TimeDelta

Source§

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

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 StructuralPartialEq for TimeDelta