pub struct TimeArithmetic { /* private fields */ }
Expand description
Options for Time::checked_add
and Time::checked_sub
.
This type provides a way to ergonomically add one of a few different
duration types to a Time
.
The main way to construct values of this type is with its From
trait
implementations:
From<Span> for TimeArithmetic
adds (or subtracts) the given span to the receiver time.From<SignedDuration> for TimeArithmetic
adds (or subtracts) the given signed duration to the receiver time.From<std::time::Duration> for TimeArithmetic
adds (or subtracts) the given unsigned duration to the receiver time.
§Example
use std::time::Duration;
use jiff::{civil::time, SignedDuration, ToSpan};
let t = time(0, 0, 0, 0);
assert_eq!(t.checked_add(2.hours())?, time(2, 0, 0, 0));
assert_eq!(t.checked_add(SignedDuration::from_hours(2))?, time(2, 0, 0, 0));
assert_eq!(t.checked_add(Duration::from_secs(2 * 60 * 60))?, time(2, 0, 0, 0));
Trait Implementations§
Source§impl Clone for TimeArithmetic
impl Clone for TimeArithmetic
Source§fn clone(&self) -> TimeArithmetic
fn clone(&self) -> TimeArithmetic
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for TimeArithmetic
impl Debug for TimeArithmetic
Source§impl<'a> From<&'a Duration> for TimeArithmetic
impl<'a> From<&'a Duration> for TimeArithmetic
Source§fn from(udur: &'a Duration) -> TimeArithmetic
fn from(udur: &'a Duration) -> TimeArithmetic
Converts to this type from the input type.
Source§impl<'a> From<&'a SignedDuration> for TimeArithmetic
impl<'a> From<&'a SignedDuration> for TimeArithmetic
Source§fn from(sdur: &'a SignedDuration) -> TimeArithmetic
fn from(sdur: &'a SignedDuration) -> TimeArithmetic
Converts to this type from the input type.
Source§impl<'a> From<&'a Span> for TimeArithmetic
impl<'a> From<&'a Span> for TimeArithmetic
Source§fn from(span: &'a Span) -> TimeArithmetic
fn from(span: &'a Span) -> TimeArithmetic
Converts to this type from the input type.
Source§impl From<Duration> for TimeArithmetic
impl From<Duration> for TimeArithmetic
Source§fn from(udur: Duration) -> TimeArithmetic
fn from(udur: Duration) -> TimeArithmetic
Converts to this type from the input type.
Source§impl From<SignedDuration> for TimeArithmetic
impl From<SignedDuration> for TimeArithmetic
Source§fn from(sdur: SignedDuration) -> TimeArithmetic
fn from(sdur: SignedDuration) -> TimeArithmetic
Converts to this type from the input type.
Source§impl From<Span> for TimeArithmetic
impl From<Span> for TimeArithmetic
Source§fn from(span: Span) -> TimeArithmetic
fn from(span: Span) -> TimeArithmetic
Converts to this type from the input type.
impl Copy for TimeArithmetic
Auto Trait Implementations§
impl Freeze for TimeArithmetic
impl RefUnwindSafe for TimeArithmetic
impl Send for TimeArithmetic
impl Sync for TimeArithmetic
impl Unpin for TimeArithmetic
impl UnwindSafe for TimeArithmetic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more