Struct TimeDelta
struct TimeDelta { ... }
Time duration with nanosecond precision.
This also allows for negative durations; see individual methods for details.
A TimeDelta is represented internally as a complement of seconds and
nanoseconds. The range is restricted to that of i64 milliseconds, with the
minimum value notably being set to -i64::MAX rather than allowing the full
range of i64::MIN. This is to allow easy flipping of sign, so that for
instance abs() can be called without any checks.
Implementations
impl TimeDelta
const fn new(secs: i64, nanos: u32) -> Option<TimeDelta>Makes a new
TimeDeltawith given number of seconds and nanoseconds.Errors
Returns
Nonewhen the duration is out of bounds, or ifnanos≥ 1,000,000,000.const fn weeks(weeks: i64) -> TimeDeltaMakes a new
TimeDeltawith 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.
const fn try_weeks(weeks: i64) -> Option<TimeDelta>Makes a new
TimeDeltawith the given number of weeks.Equivalent to
TimeDelta::try_seconds(weeks * 7 * 24 * 60 * 60)with overflow checks.Errors
Returns
Nonewhen theTimeDeltawould be out of bounds.const fn days(days: i64) -> TimeDeltaMakes a new
TimeDeltawith the given number of days.Equivalent to
TimeDelta::seconds(days * 24 * 60 * 60)with overflow checks.Panics
Panics when the
TimeDeltawould be out of bounds.const fn try_days(days: i64) -> Option<TimeDelta>Makes a new
TimeDeltawith the given number of days.Equivalent to
TimeDelta::try_seconds(days * 24 * 60 * 60)with overflow checks.Errors
Returns
Nonewhen theTimeDeltawould be out of bounds.const fn hours(hours: i64) -> TimeDeltaMakes a new
TimeDeltawith the given number of hours.Equivalent to
TimeDelta::seconds(hours * 60 * 60)with overflow checks.Panics
Panics when the
TimeDeltawould be out of bounds.const fn try_hours(hours: i64) -> Option<TimeDelta>Makes a new
TimeDeltawith the given number of hours.Equivalent to
TimeDelta::try_seconds(hours * 60 * 60)with overflow checks.Errors
Returns
Nonewhen theTimeDeltawould be out of bounds.const fn minutes(minutes: i64) -> TimeDeltaMakes a new
TimeDeltawith the given number of minutes.Equivalent to
TimeDelta::seconds(minutes * 60)with overflow checks.Panics
Panics when the
TimeDeltawould be out of bounds.const fn try_minutes(minutes: i64) -> Option<TimeDelta>Makes a new
TimeDeltawith the given number of minutes.Equivalent to
TimeDelta::try_seconds(minutes * 60)with overflow checks.Errors
Returns
Nonewhen theTimeDeltawould be out of bounds.const fn seconds(seconds: i64) -> TimeDeltaMakes a new
TimeDeltawith the given number of seconds.Panics
Panics when
secondsis more thani64::MAX / 1_000or less than-i64::MAX / 1_000(in this context, this is the same asi64::MIN / 1_000due to rounding).const fn try_seconds(seconds: i64) -> Option<TimeDelta>Makes a new
TimeDeltawith the given number of seconds.Errors
Returns
Nonewhensecondsis more thani64::MAX / 1_000or less than-i64::MAX / 1_000(in this context, this is the same asi64::MIN / 1_000due to rounding).const fn milliseconds(milliseconds: i64) -> TimeDeltaMakes a new
TimeDeltawith the given number of milliseconds.Panics
Panics when the
TimeDeltawould be out of bounds, i.e. whenmillisecondsis more thani64::MAXor less than-i64::MAX. Notably, this is not the same asi64::MIN.const fn try_milliseconds(milliseconds: i64) -> Option<TimeDelta>Makes a new
TimeDeltawith the given number of milliseconds.Errors
Returns
NonetheTimeDeltawould be out of bounds, i.e. whenmillisecondsis more thani64::MAXor less than-i64::MAX. Notably, this is not the same asi64::MIN.const fn microseconds(microseconds: i64) -> TimeDeltaMakes a new
TimeDeltawith 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.const fn nanoseconds(nanos: i64) -> TimeDeltaMakes a new
TimeDeltawith 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.const fn num_weeks(self: &Self) -> i64Returns the total number of whole weeks in the
TimeDelta.const fn num_days(self: &Self) -> i64Returns the total number of whole days in the
TimeDelta.const fn num_hours(self: &Self) -> i64Returns the total number of whole hours in the
TimeDelta.const fn num_minutes(self: &Self) -> i64Returns the total number of whole minutes in the
TimeDelta.const fn num_seconds(self: &Self) -> i64Returns the total number of whole seconds in the
TimeDelta.const fn subsec_nanos(self: &Self) -> i32Returns the number of nanoseconds such that
subsec_nanos() + num_seconds() * NANOS_PER_SECis the total number of nanoseconds in theTimeDelta.const fn num_milliseconds(self: &Self) -> i64Returns the total number of whole milliseconds in the
TimeDelta.const fn num_microseconds(self: &Self) -> Option<i64>Returns the total number of whole microseconds in the
TimeDelta, orNoneon overflow (exceeding 2^63 microseconds in either direction).const fn num_nanoseconds(self: &Self) -> Option<i64>Returns the total number of whole nanoseconds in the
TimeDelta, orNoneon overflow (exceeding 2^63 nanoseconds in either direction).const fn checked_add(self: &Self, rhs: &TimeDelta) -> Option<TimeDelta>Add two
TimeDeltas, returningNoneif overflow occurred.const fn checked_sub(self: &Self, rhs: &TimeDelta) -> Option<TimeDelta>Subtract two
TimeDeltas, returningNoneif overflow occurred.const fn checked_mul(self: &Self, rhs: i32) -> Option<TimeDelta>Multiply a
TimeDeltawith a i32, returningNoneif overflow occurred.const fn checked_div(self: &Self, rhs: i32) -> Option<TimeDelta>Divide a
TimeDeltawith a i32, returningNoneif dividing by 0.const fn abs(self: &Self) -> TimeDeltaReturns the
TimeDeltaas an absolute (non-negative) value.const fn min_value() -> TimeDeltaThe minimum possible
TimeDelta:-i64::MAXmilliseconds.const fn max_value() -> TimeDeltaThe maximum possible
TimeDelta:i64::MAXmilliseconds.const fn zero() -> TimeDeltaA
TimeDeltawhere the stored seconds and nanoseconds are equal to zero.const fn is_zero(self: &Self) -> boolReturns
trueif theTimeDeltaequalsTimeDelta::zero().const fn from_std(duration: Duration) -> Result<TimeDelta, OutOfRangeError>Creates a
TimeDeltaobject fromstd::time::DurationThis function errors when original duration is larger than the maximum value supported for this type.
const fn to_std(self: &Self) -> Result<Duration, OutOfRangeError>Creates a
std::time::Durationobject from aTimeDelta.This function errors when duration is less than zero. As standard library implementation is limited to non-negative values.
impl Add for TimeDelta
fn add(self: Self, rhs: TimeDelta) -> TimeDelta
impl AddAssign for TimeDelta
fn add_assign(self: &mut Self, rhs: TimeDelta)
impl Clone for TimeDelta
fn clone(self: &Self) -> TimeDelta
impl Copy for TimeDelta
impl Debug for TimeDelta
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for TimeDelta
fn default() -> TimeDelta
impl Display for TimeDelta
fn fmt(self: &Self, f: &mut Formatter<'_>) -> ResultFormat a
TimeDeltausing the ISO 8601 format
impl Div for TimeDelta
fn div(self: Self, rhs: i32) -> TimeDelta
impl Eq for TimeDelta
impl Freeze for TimeDelta
impl Hash for TimeDelta
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Mul for TimeDelta
fn mul(self: Self, rhs: i32) -> TimeDelta
impl Neg for TimeDelta
fn neg(self: Self) -> TimeDelta
impl Ord for TimeDelta
fn cmp(self: &Self, other: &TimeDelta) -> Ordering
impl PartialEq for TimeDelta
fn eq(self: &Self, other: &TimeDelta) -> bool
impl PartialOrd for TimeDelta
fn partial_cmp(self: &Self, other: &TimeDelta) -> Option<Ordering>
impl RefUnwindSafe for TimeDelta
impl Send for TimeDelta
impl StructuralPartialEq for TimeDelta
impl Sub for TimeDelta
fn sub(self: Self, rhs: TimeDelta) -> TimeDelta
impl SubAssign for TimeDelta
fn sub_assign(self: &mut Self, rhs: TimeDelta)
impl Sum for TimeDelta
fn sum<I: Iterator<Item = TimeDelta>>(iter: I) -> TimeDelta
impl Sync for TimeDelta
impl Unpin for TimeDelta
impl UnsafeUnpin for TimeDelta
impl UnwindSafe for TimeDelta
impl<'a> Sum for TimeDelta
fn sum<I: Iterator<Item = &'a TimeDelta>>(iter: I) -> TimeDelta
impl<T> Any for TimeDelta
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for TimeDelta
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for TimeDelta
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for TimeDelta
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for TimeDelta
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for TimeDelta
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for TimeDelta
fn to_string(self: &Self) -> String
impl<T, U> Into for TimeDelta
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for TimeDelta
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for TimeDelta
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>