pub struct TimestampArithmetic { /* private fields */ }
Expand description
Options for Timestamp::checked_add
and Timestamp::checked_sub
.
This type provides a way to ergonomically add one of a few different
duration types to a Timestamp
.
The main way to construct values of this type is with its From
trait
implementations:
From<Span> for TimestampArithmetic
adds (or subtracts) the given span to the receiver timestamp.From<SignedDuration> for TimestampArithmetic
adds (or subtracts) the given signed duration to the receiver timestamp.From<std::time::Duration> for TimestampArithmetic
adds (or subtracts) the given unsigned duration to the receiver timestamp.
§Example
use std::time::Duration;
use jiff::{SignedDuration, Timestamp, ToSpan};
let ts: Timestamp = "2024-02-28T00:00:00Z".parse()?;
assert_eq!(
ts.checked_add(48.hours())?,
"2024-03-01T00:00:00Z".parse()?,
);
assert_eq!(
ts.checked_add(SignedDuration::from_hours(48))?,
"2024-03-01T00:00:00Z".parse()?,
);
assert_eq!(
ts.checked_add(Duration::from_secs(48 * 60 * 60))?,
"2024-03-01T00:00:00Z".parse()?,
);
Trait Implementations§
Source§impl Clone for TimestampArithmetic
impl Clone for TimestampArithmetic
Source§fn clone(&self) -> TimestampArithmetic
fn clone(&self) -> TimestampArithmetic
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 TimestampArithmetic
impl Debug for TimestampArithmetic
Source§impl<'a> From<&'a Duration> for TimestampArithmetic
impl<'a> From<&'a Duration> for TimestampArithmetic
Source§fn from(udur: &'a Duration) -> TimestampArithmetic
fn from(udur: &'a Duration) -> TimestampArithmetic
Converts to this type from the input type.
Source§impl<'a> From<&'a SignedDuration> for TimestampArithmetic
impl<'a> From<&'a SignedDuration> for TimestampArithmetic
Source§fn from(sdur: &'a SignedDuration) -> TimestampArithmetic
fn from(sdur: &'a SignedDuration) -> TimestampArithmetic
Converts to this type from the input type.
Source§impl<'a> From<&'a Span> for TimestampArithmetic
impl<'a> From<&'a Span> for TimestampArithmetic
Source§fn from(span: &'a Span) -> TimestampArithmetic
fn from(span: &'a Span) -> TimestampArithmetic
Converts to this type from the input type.
Source§impl From<Duration> for TimestampArithmetic
impl From<Duration> for TimestampArithmetic
Source§fn from(udur: Duration) -> TimestampArithmetic
fn from(udur: Duration) -> TimestampArithmetic
Converts to this type from the input type.
Source§impl From<SignedDuration> for TimestampArithmetic
impl From<SignedDuration> for TimestampArithmetic
Source§fn from(sdur: SignedDuration) -> TimestampArithmetic
fn from(sdur: SignedDuration) -> TimestampArithmetic
Converts to this type from the input type.
Source§impl From<Span> for TimestampArithmetic
impl From<Span> for TimestampArithmetic
Source§fn from(span: Span) -> TimestampArithmetic
fn from(span: Span) -> TimestampArithmetic
Converts to this type from the input type.
impl Copy for TimestampArithmetic
Auto Trait Implementations§
impl Freeze for TimestampArithmetic
impl RefUnwindSafe for TimestampArithmetic
impl Send for TimestampArithmetic
impl Sync for TimestampArithmetic
impl Unpin for TimestampArithmetic
impl UnwindSafe for TimestampArithmetic
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