Struct DateTimeArithmetic

struct DateTimeArithmetic { ... }

Options for DateTime::checked_add and DateTime::checked_sub.

This type provides a way to ergonomically add one of a few different duration types to a DateTime.

The main way to construct values of this type is with its From trait implementations:

Example

use std::time::Duration;

use jiff::{civil::date, SignedDuration, ToSpan};

let dt = date(2024, 2, 29).at(0, 0, 0, 0);
assert_eq!(
    dt.checked_add(1.year())?,
    date(2025, 2, 28).at(0, 0, 0, 0),
);
assert_eq!(
    dt.checked_add(SignedDuration::from_hours(24))?,
    date(2024, 3, 1).at(0, 0, 0, 0),
);
assert_eq!(
    dt.checked_add(Duration::from_secs(24 * 60 * 60))?,
    date(2024, 3, 1).at(0, 0, 0, 0),
);

# Ok::<(), Box<dyn std::error::Error>>(())

Implementations

impl Clone for DateTimeArithmetic

fn clone(self: &Self) -> DateTimeArithmetic

impl Copy for DateTimeArithmetic

impl Debug for DateTimeArithmetic

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Freeze for DateTimeArithmetic

impl From for DateTimeArithmetic

fn from(span: Span) -> DateTimeArithmetic

impl From for DateTimeArithmetic

fn from(sdur: SignedDuration) -> DateTimeArithmetic

impl From for DateTimeArithmetic

fn from(udur: UnsignedDuration) -> DateTimeArithmetic

impl RefUnwindSafe for DateTimeArithmetic

impl Send for DateTimeArithmetic

impl Sync for DateTimeArithmetic

impl Unpin for DateTimeArithmetic

impl UnsafeUnpin for DateTimeArithmetic

impl UnwindSafe for DateTimeArithmetic

impl<'a> From for DateTimeArithmetic

fn from(span: &'a Span) -> DateTimeArithmetic

impl<'a> From for DateTimeArithmetic

fn from(sdur: &'a SignedDuration) -> DateTimeArithmetic

impl<'a> From for DateTimeArithmetic

fn from(udur: &'a UnsignedDuration) -> DateTimeArithmetic

impl<T> Any for DateTimeArithmetic

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for DateTimeArithmetic

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for DateTimeArithmetic

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for DateTimeArithmetic

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for DateTimeArithmetic

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for DateTimeArithmetic

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for DateTimeArithmetic

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for DateTimeArithmetic

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for DateTimeArithmetic

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>