pub struct DateArithmetic { /* private fields */ }
Expand description
Options for Date::checked_add
and Date::checked_sub
.
This type provides a way to ergonomically add one of a few different
duration types to a Date
.
The main way to construct values of this type is with its From
trait
implementations:
From<Span> for DateArithmetic
adds (or subtracts) the given span to the receiver date.From<SignedDuration> for DateArithmetic
adds (or subtracts) the given signed duration to the receiver date.From<std::time::Duration> for DateArithmetic
adds (or subtracts) the given unsigned duration to the receiver date.
§Example
use std::time::Duration;
use jiff::{civil::date, SignedDuration, ToSpan};
let d = date(2024, 2, 29);
assert_eq!(d.checked_add(1.year())?, date(2025, 2, 28));
assert_eq!(d.checked_add(SignedDuration::from_hours(24))?, date(2024, 3, 1));
assert_eq!(d.checked_add(Duration::from_secs(24 * 60 * 60))?, date(2024, 3, 1));
Trait Implementations§
Source§impl Clone for DateArithmetic
impl Clone for DateArithmetic
Source§fn clone(&self) -> DateArithmetic
fn clone(&self) -> DateArithmetic
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 DateArithmetic
impl Debug for DateArithmetic
Source§impl<'a> From<&'a Duration> for DateArithmetic
impl<'a> From<&'a Duration> for DateArithmetic
Source§fn from(udur: &'a UnsignedDuration) -> DateArithmetic
fn from(udur: &'a UnsignedDuration) -> DateArithmetic
Converts to this type from the input type.
Source§impl<'a> From<&'a SignedDuration> for DateArithmetic
impl<'a> From<&'a SignedDuration> for DateArithmetic
Source§fn from(sdur: &'a SignedDuration) -> DateArithmetic
fn from(sdur: &'a SignedDuration) -> DateArithmetic
Converts to this type from the input type.
Source§impl<'a> From<&'a Span> for DateArithmetic
impl<'a> From<&'a Span> for DateArithmetic
Source§fn from(span: &'a Span) -> DateArithmetic
fn from(span: &'a Span) -> DateArithmetic
Converts to this type from the input type.
Source§impl From<Duration> for DateArithmetic
impl From<Duration> for DateArithmetic
Source§fn from(udur: UnsignedDuration) -> DateArithmetic
fn from(udur: UnsignedDuration) -> DateArithmetic
Converts to this type from the input type.
Source§impl From<SignedDuration> for DateArithmetic
impl From<SignedDuration> for DateArithmetic
Source§fn from(sdur: SignedDuration) -> DateArithmetic
fn from(sdur: SignedDuration) -> DateArithmetic
Converts to this type from the input type.
Source§impl From<Span> for DateArithmetic
impl From<Span> for DateArithmetic
Source§fn from(span: Span) -> DateArithmetic
fn from(span: Span) -> DateArithmetic
Converts to this type from the input type.
impl Copy for DateArithmetic
Auto Trait Implementations§
impl Freeze for DateArithmetic
impl RefUnwindSafe for DateArithmetic
impl Send for DateArithmetic
impl Sync for DateArithmetic
impl Unpin for DateArithmetic
impl UnwindSafe for DateArithmetic
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