Struct cursive::reexports::time::Duration [−]
pub struct Duration { /* fields omitted */ }
Expand description
A span of time with nanosecond precision.
Each Duration
is composed of a whole number of seconds and a fractional part represented in
nanoseconds.
This implementation allows for negative durations, unlike core::time::Duration
.
Implementations
impl Duration
impl Duration
pub const NANOSECOND: Duration
pub const NANOSECOND: Duration
Equivalent to 1.nanoseconds()
.
assert_eq!(Duration::NANOSECOND, 1.nanoseconds());
pub const MICROSECOND: Duration
pub const MICROSECOND: Duration
Equivalent to 1.microseconds()
.
assert_eq!(Duration::MICROSECOND, 1.microseconds());
pub const MILLISECOND: Duration
pub const MILLISECOND: Duration
Equivalent to 1.milliseconds()
.
assert_eq!(Duration::MILLISECOND, 1.milliseconds());
The minimum possible duration. Adding any negative duration to this will cause an overflow.
The maximum possible duration. Adding any positive duration to this will cause an overflow.
Check if a duration is exactly zero.
assert!(0.seconds().is_zero());
assert!(!1.nanoseconds().is_zero());
pub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Check if a duration is negative.
assert!((-1).seconds().is_negative());
assert!(!0.seconds().is_negative());
assert!(!1.seconds().is_negative());
pub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Check if a duration is positive.
assert!(1.seconds().is_positive());
assert!(!0.seconds().is_positive());
assert!(!(-1).seconds().is_positive());
Get the absolute value of the duration.
This method saturates the returned value if it would otherwise overflow.
assert_eq!(1.seconds().abs(), 1.seconds());
assert_eq!(0.seconds().abs(), 0.seconds());
assert_eq!((-1).seconds().abs(), 1.seconds());
Create a new Duration
with the provided seconds and nanoseconds. If nanoseconds is at
least ±109, it will wrap to the number of seconds.
assert_eq!(Duration::new(1, 0), 1.seconds());
assert_eq!(Duration::new(-1, 0), (-1).seconds());
assert_eq!(Duration::new(1, 2_000_000_000), 3.seconds());
Create a new Duration
with the given number of weeks. Equivalent to
Duration::seconds(weeks * 604_800)
.
assert_eq!(Duration::weeks(1), 604_800.seconds());
Create a new Duration
with the given number of days. Equivalent to
Duration::seconds(days * 86_400)
.
assert_eq!(Duration::days(1), 86_400.seconds());
Create a new Duration
with the given number of hours. Equivalent to
Duration::seconds(hours * 3_600)
.
assert_eq!(Duration::hours(1), 3_600.seconds());
Create a new Duration
with the given number of minutes. Equivalent to
Duration::seconds(minutes * 60)
.
assert_eq!(Duration::minutes(1), 60.seconds());
Create a new Duration
with the given number of seconds.
assert_eq!(Duration::seconds(1), 1_000.milliseconds());
pub fn seconds_f64(seconds: f64) -> Duration
pub fn seconds_f64(seconds: f64) -> Duration
Creates a new Duration
from the specified number of seconds represented as f64
.
assert_eq!(Duration::seconds_f64(0.5), 0.5.seconds());
assert_eq!(Duration::seconds_f64(-0.5), -0.5.seconds());
pub fn seconds_f32(seconds: f32) -> Duration
pub fn seconds_f32(seconds: f32) -> Duration
Creates a new Duration
from the specified number of seconds represented as f32
.
assert_eq!(Duration::seconds_f32(0.5), 0.5.seconds());
assert_eq!(Duration::seconds_f32(-0.5), (-0.5).seconds());
pub const fn milliseconds(milliseconds: i64) -> Duration
pub const fn milliseconds(milliseconds: i64) -> Duration
Create a new Duration
with the given number of milliseconds.
assert_eq!(Duration::milliseconds(1), 1_000.microseconds());
assert_eq!(Duration::milliseconds(-1), (-1_000).microseconds());
pub const fn microseconds(microseconds: i64) -> Duration
pub const fn microseconds(microseconds: i64) -> Duration
Create a new Duration
with the given number of microseconds.
assert_eq!(Duration::microseconds(1), 1_000.nanoseconds());
assert_eq!(Duration::microseconds(-1), (-1_000).nanoseconds());
pub const fn nanoseconds(nanoseconds: i64) -> Duration
pub const fn nanoseconds(nanoseconds: i64) -> Duration
Create a new Duration
with the given number of nanoseconds.
assert_eq!(Duration::nanoseconds(1), 1.microseconds() / 1_000);
assert_eq!(Duration::nanoseconds(-1), (-1).microseconds() / 1_000);
pub const fn whole_weeks(self) -> i64
pub const fn whole_weeks(self) -> i64
Get the number of whole weeks in the duration.
assert_eq!(1.weeks().whole_weeks(), 1);
assert_eq!((-1).weeks().whole_weeks(), -1);
assert_eq!(6.days().whole_weeks(), 0);
assert_eq!((-6).days().whole_weeks(), 0);
pub const fn whole_days(self) -> i64
pub const fn whole_days(self) -> i64
Get the number of whole days in the duration.
assert_eq!(1.days().whole_days(), 1);
assert_eq!((-1).days().whole_days(), -1);
assert_eq!(23.hours().whole_days(), 0);
assert_eq!((-23).hours().whole_days(), 0);
pub const fn whole_hours(self) -> i64
pub const fn whole_hours(self) -> i64
Get the number of whole hours in the duration.
assert_eq!(1.hours().whole_hours(), 1);
assert_eq!((-1).hours().whole_hours(), -1);
assert_eq!(59.minutes().whole_hours(), 0);
assert_eq!((-59).minutes().whole_hours(), 0);
pub const fn whole_minutes(self) -> i64
pub const fn whole_minutes(self) -> i64
Get the number of whole minutes in the duration.
assert_eq!(1.minutes().whole_minutes(), 1);
assert_eq!((-1).minutes().whole_minutes(), -1);
assert_eq!(59.seconds().whole_minutes(), 0);
assert_eq!((-59).seconds().whole_minutes(), 0);
pub const fn whole_seconds(self) -> i64
pub const fn whole_seconds(self) -> i64
Get the number of whole seconds in the duration.
assert_eq!(1.seconds().whole_seconds(), 1);
assert_eq!((-1).seconds().whole_seconds(), -1);
assert_eq!(1.minutes().whole_seconds(), 60);
assert_eq!((-1).minutes().whole_seconds(), -60);
pub fn as_seconds_f64(self) -> f64
pub fn as_seconds_f64(self) -> f64
Get the number of fractional seconds in the duration.
assert_eq!(1.5.seconds().as_seconds_f64(), 1.5);
assert_eq!((-1.5).seconds().as_seconds_f64(), -1.5);
pub fn as_seconds_f32(self) -> f32
pub fn as_seconds_f32(self) -> f32
Get the number of fractional seconds in the duration.
assert_eq!(1.5.seconds().as_seconds_f32(), 1.5);
assert_eq!((-1.5).seconds().as_seconds_f32(), -1.5);
pub const fn whole_milliseconds(self) -> i128
pub const fn whole_milliseconds(self) -> i128
Get the number of whole milliseconds in the duration.
assert_eq!(1.seconds().whole_milliseconds(), 1_000);
assert_eq!((-1).seconds().whole_milliseconds(), -1_000);
assert_eq!(1.milliseconds().whole_milliseconds(), 1);
assert_eq!((-1).milliseconds().whole_milliseconds(), -1);
pub const fn subsec_milliseconds(self) -> i16
pub const fn subsec_milliseconds(self) -> i16
Get the number of milliseconds past the number of whole seconds.
Always in the range -1_000..1_000
.
assert_eq!(1.4.seconds().subsec_milliseconds(), 400);
assert_eq!((-1.4).seconds().subsec_milliseconds(), -400);
pub const fn whole_microseconds(self) -> i128
pub const fn whole_microseconds(self) -> i128
Get the number of whole microseconds in the duration.
assert_eq!(1.milliseconds().whole_microseconds(), 1_000);
assert_eq!((-1).milliseconds().whole_microseconds(), -1_000);
assert_eq!(1.microseconds().whole_microseconds(), 1);
assert_eq!((-1).microseconds().whole_microseconds(), -1);
pub const fn subsec_microseconds(self) -> i32
pub const fn subsec_microseconds(self) -> i32
Get the number of microseconds past the number of whole seconds.
Always in the range -1_000_000..1_000_000
.
assert_eq!(1.0004.seconds().subsec_microseconds(), 400);
assert_eq!((-1.0004).seconds().subsec_microseconds(), -400);
pub const fn whole_nanoseconds(self) -> i128
pub const fn whole_nanoseconds(self) -> i128
Get the number of nanoseconds in the duration.
assert_eq!(1.microseconds().whole_nanoseconds(), 1_000);
assert_eq!((-1).microseconds().whole_nanoseconds(), -1_000);
assert_eq!(1.nanoseconds().whole_nanoseconds(), 1);
assert_eq!((-1).nanoseconds().whole_nanoseconds(), -1);
pub const fn subsec_nanoseconds(self) -> i32
pub const fn subsec_nanoseconds(self) -> i32
Get the number of nanoseconds past the number of whole seconds.
The returned value will always be in the range -1_000_000_000..1_000_000_000
.
assert_eq!(1.000_000_400.seconds().subsec_nanoseconds(), 400);
assert_eq!((-1.000_000_400).seconds().subsec_nanoseconds(), -400);
pub const fn checked_add(self, rhs: Duration) -> Option<Duration>
pub const fn checked_add(self, rhs: Duration) -> Option<Duration>
Computes self + rhs
, returning None
if an overflow occurred.
assert_eq!(5.seconds().checked_add(5.seconds()), Some(10.seconds()));
assert_eq!(Duration::MAX.checked_add(1.nanoseconds()), None);
assert_eq!((-5).seconds().checked_add(5.seconds()), Some(0.seconds()));
pub const fn checked_sub(self, rhs: Duration) -> Option<Duration>
pub const fn checked_sub(self, rhs: Duration) -> Option<Duration>
Computes self - rhs
, returning None
if an overflow occurred.
assert_eq!(5.seconds().checked_sub(5.seconds()), Some(Duration::ZERO));
assert_eq!(Duration::MIN.checked_sub(1.nanoseconds()), None);
assert_eq!(5.seconds().checked_sub(10.seconds()), Some((-5).seconds()));
pub const fn checked_mul(self, rhs: i32) -> Option<Duration>
pub const fn checked_mul(self, rhs: i32) -> Option<Duration>
Computes self * rhs
, returning None
if an overflow occurred.
assert_eq!(5.seconds().checked_mul(2), Some(10.seconds()));
assert_eq!(5.seconds().checked_mul(-2), Some((-10).seconds()));
assert_eq!(5.seconds().checked_mul(0), Some(0.seconds()));
assert_eq!(Duration::MAX.checked_mul(2), None);
assert_eq!(Duration::MIN.checked_mul(2), None);
pub fn checked_div(self, rhs: i32) -> Option<Duration>
pub fn checked_div(self, rhs: i32) -> Option<Duration>
Computes self / rhs
, returning None
if rhs == 0
or if the result would overflow.
assert_eq!(10.seconds().checked_div(2), Some(5.seconds()));
assert_eq!(10.seconds().checked_div(-2), Some((-5).seconds()));
assert_eq!(1.seconds().checked_div(0), None);
pub const fn saturating_add(self, rhs: Duration) -> Duration
pub const fn saturating_add(self, rhs: Duration) -> Duration
Computes self + rhs
, saturating if an overflow occurred.
assert_eq!(5.seconds().saturating_add(5.seconds()), 10.seconds());
assert_eq!(Duration::MAX.saturating_add(1.nanoseconds()), Duration::MAX);
assert_eq!(
Duration::MIN.saturating_add((-1).nanoseconds()),
Duration::MIN
);
assert_eq!((-5).seconds().saturating_add(5.seconds()), Duration::ZERO);
pub const fn saturating_sub(self, rhs: Duration) -> Duration
pub const fn saturating_sub(self, rhs: Duration) -> Duration
Computes self - rhs
, saturating if an overflow occurred.
assert_eq!(5.seconds().saturating_sub(5.seconds()), Duration::ZERO);
assert_eq!(Duration::MIN.saturating_sub(1.nanoseconds()), Duration::MIN);
assert_eq!(
Duration::MAX.saturating_sub((-1).nanoseconds()),
Duration::MAX
);
assert_eq!(5.seconds().saturating_sub(10.seconds()), (-5).seconds());
pub const fn saturating_mul(self, rhs: i32) -> Duration
pub const fn saturating_mul(self, rhs: i32) -> Duration
Computes self * rhs
, saturating if an overflow occurred.
assert_eq!(5.seconds().saturating_mul(2), 10.seconds());
assert_eq!(5.seconds().saturating_mul(-2), (-10).seconds());
assert_eq!(5.seconds().saturating_mul(0), Duration::ZERO);
assert_eq!(Duration::MAX.saturating_mul(2), Duration::MAX);
assert_eq!(Duration::MIN.saturating_mul(2), Duration::MIN);
assert_eq!(Duration::MAX.saturating_mul(-2), Duration::MIN);
assert_eq!(Duration::MIN.saturating_mul(-2), Duration::MAX);
Trait Implementations
impl Add<Duration> for SystemTime
impl Add<Duration> for SystemTime
type Output = SystemTime
type Output = SystemTime
The resulting type after applying the +
operator.
impl Add<Duration> for PrimitiveDateTime
impl Add<Duration> for PrimitiveDateTime
type Output = PrimitiveDateTime
type Output = PrimitiveDateTime
The resulting type after applying the +
operator.
Add the sub-day time of the Duration
to the Time
. Wraps on overflow.
assert_eq!(time!(12:00) + 2.hours(), time!(14:00));
assert_eq!(time!(0:00:01) + (-2).seconds(), time!(23:59:59));
pub fn add_assign(&mut self, rhs: Duration)
pub fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
impl AddAssign<Duration> for PrimitiveDateTime
impl AddAssign<Duration> for PrimitiveDateTime
pub fn add_assign(&mut self, rhs: Duration)
pub fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
pub fn add_assign(&mut self, rhs: Duration)
pub fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
pub fn add_assign(&mut self, rhs: Duration)
pub fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
pub fn add_assign(&mut self, rhs: Duration)
pub fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
impl AddAssign<Duration> for OffsetDateTime
impl AddAssign<Duration> for OffsetDateTime
pub fn add_assign(&mut self, rhs: Duration)
pub fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
pub fn add_assign(&mut self, rhs: Duration)
pub fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
impl AddAssign<Duration> for SystemTime
impl AddAssign<Duration> for SystemTime
pub fn add_assign(&mut self, rhs: Duration)
pub fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
pub fn add_assign(&mut self, rhs: Duration)
pub fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
pub fn div_assign(&mut self, rhs: f32)
pub fn div_assign(&mut self, rhs: f32)
Performs the /=
operation. Read more
pub fn div_assign(&mut self, rhs: f64)
pub fn div_assign(&mut self, rhs: f64)
Performs the /=
operation. Read more
pub fn div_assign(&mut self, rhs: i16)
pub fn div_assign(&mut self, rhs: i16)
Performs the /=
operation. Read more
pub fn div_assign(&mut self, rhs: i32)
pub fn div_assign(&mut self, rhs: i32)
Performs the /=
operation. Read more
pub fn div_assign(&mut self, rhs: i8)
pub fn div_assign(&mut self, rhs: i8)
Performs the /=
operation. Read more
pub fn div_assign(&mut self, rhs: u16)
pub fn div_assign(&mut self, rhs: u16)
Performs the /=
operation. Read more
pub fn div_assign(&mut self, rhs: u32)
pub fn div_assign(&mut self, rhs: u32)
Performs the /=
operation. Read more
pub fn div_assign(&mut self, rhs: u8)
pub fn div_assign(&mut self, rhs: u8)
Performs the /=
operation. Read more
pub fn mul_assign(&mut self, rhs: f32)
pub fn mul_assign(&mut self, rhs: f32)
Performs the *=
operation. Read more
pub fn mul_assign(&mut self, rhs: f64)
pub fn mul_assign(&mut self, rhs: f64)
Performs the *=
operation. Read more
pub fn mul_assign(&mut self, rhs: i16)
pub fn mul_assign(&mut self, rhs: i16)
Performs the *=
operation. Read more
pub fn mul_assign(&mut self, rhs: i32)
pub fn mul_assign(&mut self, rhs: i32)
Performs the *=
operation. Read more
pub fn mul_assign(&mut self, rhs: i8)
pub fn mul_assign(&mut self, rhs: i8)
Performs the *=
operation. Read more
pub fn mul_assign(&mut self, rhs: u16)
pub fn mul_assign(&mut self, rhs: u16)
Performs the *=
operation. Read more
pub fn mul_assign(&mut self, rhs: u32)
pub fn mul_assign(&mut self, rhs: u32)
Performs the *=
operation. Read more
pub fn mul_assign(&mut self, rhs: u8)
pub fn mul_assign(&mut self, rhs: u8)
Performs the *=
operation. Read more
impl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
pub fn partial_cmp(&self, rhs: &Duration) -> Option<Ordering>
pub fn partial_cmp(&self, rhs: &Duration) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
pub fn partial_cmp(&self, rhs: &Duration) -> Option<Ordering>
pub fn partial_cmp(&self, rhs: &Duration) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
pub fn partial_cmp(&self, other: &Duration) -> Option<Ordering>
pub fn partial_cmp(&self, other: &Duration) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Subtract the sub-day time of the Duration
from the Time
. Wraps on overflow.
assert_eq!(time!(14:00) - 2.hours(), time!(12:00));
assert_eq!(time!(23:59:59) - (-2).seconds(), time!(0:00:01));
impl Sub<Duration> for SystemTime
impl Sub<Duration> for SystemTime
type Output = SystemTime
type Output = SystemTime
The resulting type after applying the -
operator.
impl Sub<Duration> for PrimitiveDateTime
impl Sub<Duration> for PrimitiveDateTime
type Output = PrimitiveDateTime
type Output = PrimitiveDateTime
The resulting type after applying the -
operator.
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
impl SubAssign<Duration> for OffsetDateTime
impl SubAssign<Duration> for OffsetDateTime
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
impl SubAssign<Duration> for SystemTime
impl SubAssign<Duration> for SystemTime
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
impl SubAssign<Duration> for PrimitiveDateTime
impl SubAssign<Duration> for PrimitiveDateTime
pub fn sub_assign(&mut self, rhs: Duration)
pub fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
type Error = ConversionRange
type Error = ConversionRange
The type returned in the event of a conversion error.
pub fn try_from(original: Duration) -> Result<Duration, ConversionRange>
pub fn try_from(original: Duration) -> Result<Duration, ConversionRange>
Performs the conversion.
type Error = ConversionRange
type Error = ConversionRange
The type returned in the event of a conversion error.
pub fn try_from(duration: Duration) -> Result<Duration, ConversionRange>
pub fn try_from(duration: Duration) -> Result<Duration, ConversionRange>
Performs the conversion.
impl StructuralEq for Duration
impl StructuralPartialEq for Duration
Auto Trait Implementations
impl RefUnwindSafe for Duration
impl UnwindSafe for Duration
Blanket Implementations
Mutably borrows from an owned value. Read more
Calls the given closure and return the result. Read more
Calls the given closure on self
.