Skip to main content

Duration

Struct Duration 

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

A signed span of time with nanosecond precision.

Implementations§

Source§

impl Duration

Source

pub const ZERO: Self

Zero.

Source

pub const MAX: Self

The largest span: i64::MAX milliseconds, the range LeanCTX’s durations have always had; the smallest is its negation.

Source

pub const MIN: Self

The smallest span: -i64::MAX milliseconds.

Source

pub const fn zero() -> Self

Zero.

Source

pub const fn weeks(n: i64) -> Self

n weeks. Panics when the span does not fit.

Source

pub const fn try_weeks(n: i64) -> Option<Self>

n weeks. None when the span does not fit.

Source

pub const fn days(n: i64) -> Self

n days of 24 hours. Panics when the span does not fit.

Source

pub const fn try_days(n: i64) -> Option<Self>

n days of 24 hours. None when the span does not fit.

Source

pub const fn hours(n: i64) -> Self

n hours. Panics when the span does not fit.

Source

pub const fn try_hours(n: i64) -> Option<Self>

n hours. None when the span does not fit.

Source

pub const fn minutes(n: i64) -> Self

n minutes. Panics when the span does not fit.

Source

pub const fn try_minutes(n: i64) -> Option<Self>

n minutes. None when the span does not fit.

Source

pub const fn seconds(n: i64) -> Self

n seconds. Panics when the span does not fit.

Source

pub const fn try_seconds(n: i64) -> Option<Self>

n seconds. None when the span does not fit.

Source

pub const fn milliseconds(n: i64) -> Self

n milliseconds. Panics when the span does not fit.

Source

pub const fn try_milliseconds(n: i64) -> Option<Self>

n milliseconds. None when the span does not fit.

Source

pub const fn microseconds(n: i64) -> Self

n microseconds. Panics when the span does not fit.

Source

pub const fn try_microseconds(n: i64) -> Option<Self>

n microseconds. None when the span does not fit.

Source

pub fn nanoseconds(n: i64) -> Self

n nanoseconds.

Source

pub fn num_weeks(self) -> i64

Whole weeks, truncated towards zero.

Source

pub fn num_days(self) -> i64

Whole days, truncated towards zero.

Source

pub fn num_hours(self) -> i64

Whole hours, truncated towards zero.

Source

pub fn num_minutes(self) -> i64

Whole minutes, truncated towards zero.

Source

pub fn num_seconds(self) -> i64

Whole seconds, truncated towards zero.

Source

pub fn num_milliseconds(self) -> i64

Whole milliseconds, truncated towards zero.

Source

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

Whole microseconds, truncated towards zero; None past i64.

Source

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

Nanoseconds; None past i64.

Source

pub fn subsec_nanos(self) -> i32

The nanoseconds past Duration::num_seconds, with its sign.

Source

pub fn as_seconds_f64(self) -> f64

Whole seconds as f64, with the fraction.

Source

pub fn is_zero(self) -> bool

Zero?

Source

pub fn is_negative(self) -> bool

Below zero?

Source

pub fn abs(self) -> Self

The absolute value.

Source

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

self + rhs, None outside Duration::MIN..=Duration::MAX.

Source

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

self - rhs, None outside Duration::MIN..=Duration::MAX.

Source

pub fn from_std(d: Duration) -> Result<Self, OutOfRangeError>

From a std duration; Err past Duration::MAX.

Source

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

To a std duration; Err when negative.

Source

pub const fn from_jiff(d: SignedDuration) -> Self

Wraps a jiff signed duration.

Source

pub const fn as_jiff(self) -> SignedDuration

The jiff signed duration underneath.

Trait Implementations§

Source§

impl Add for Duration

Source§

type Output = Duration

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Duration> for Date

Source§

type Output = Date

The resulting type after applying the + operator.
Source§

fn add(self, d: Duration) -> Date

Performs the + operation. Read more
Source§

impl Add<Duration> for CivilDateTime

Source§

type Output = DateTime

The resulting type after applying the + operator.
Source§

fn add(self, d: Duration) -> CivilDateTime

Performs the + operation. Read more
Source§

impl Add<Duration> for UtcDateTime

Source§

type Output = UtcDateTime

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Duration> for OffsetDateTime

Source§

type Output = OffsetDateTime

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Duration

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl AddAssign<Duration> for UtcDateTime

Source§

fn add_assign(&mut self, d: Duration)

Performs the += operation. Read more
Source§

impl Clone for Duration

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Duration

Source§

impl Debug for Duration

Source§

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

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

impl Default for Duration

Source§

fn default() -> Self

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

impl Display for Duration

Source§

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

ISO 8601 in seconds: PT90S, PT0.25S, -PT1.5S, P0D for zero.

Source§

impl Div<i32> for Duration

Source§

type Output = Duration

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Eq for Duration

Source§

impl Hash for Duration

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 Duration

Source§

type Output = Duration

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for Duration

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Ord for Duration

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Duration

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Duration

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for Duration

Source§

impl Sub for Duration

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Duration> for Date

Source§

type Output = Date

The resulting type after applying the - operator.
Source§

fn sub(self, d: Duration) -> Date

Performs the - operation. Read more
Source§

impl Sub<Duration> for CivilDateTime

Source§

type Output = DateTime

The resulting type after applying the - operator.
Source§

fn sub(self, d: Duration) -> CivilDateTime

Performs the - operation. Read more
Source§

impl Sub<Duration> for UtcDateTime

Source§

type Output = UtcDateTime

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Duration> for OffsetDateTime

Source§

type Output = OffsetDateTime

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Duration

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl SubAssign<Duration> for UtcDateTime

Source§

fn sub_assign(&mut self, d: Duration)

Performs the -= operation. Read more
Source§

impl Sum for Duration

Source§

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

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

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

Source§

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

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

Auto Trait Implementations§

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

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

fn try_from(value: U) -> Result<T, !>

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.