Struct DateTimeArithmetic

pub struct DateTimeArithmetic { /* private fields */ }

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>>(())

Trait Implementations

impl Clone for DateTimeArithmetic

fn clone(&self) -> Self

impl Copy for DateTimeArithmetic

impl Debug for DateTimeArithmetic

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

impl From<Duration> for DateTimeArithmetic

fn from(udur: UnsignedDuration) -> DateTimeArithmetic

impl From<SignedDuration> for DateTimeArithmetic

fn from(sdur: SignedDuration) -> DateTimeArithmetic

impl From<Span> for DateTimeArithmetic

fn from(span: Span) -> DateTimeArithmetic

impl<'a> From<&'a Duration> for DateTimeArithmetic

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

impl<'a> From<&'a SignedDuration> for DateTimeArithmetic

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

impl<'a> From<&'a Span> for DateTimeArithmetic

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

Auto Trait Implementations

impl Freeze for 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

Blanket Implementations

impl<T> Any for DateTimeArithmetic where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for DateTimeArithmetic where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for DateTimeArithmetic where T: ?Sized,

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

impl<T> CloneToUninit for DateTimeArithmetic where T: Clone,

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

impl<T> From<T> for DateTimeArithmetic

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for DateTimeArithmetic where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for DateTimeArithmetic where U: From<T>,

fn into(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<U> for DateTimeArithmetic where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for DateTimeArithmetic where U: TryFrom<T>,

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