pub struct MonthInterval { /* private fields */ }
Expand description
An interval of months.
Unlike DateInterval
, this only represents positive numbers of months, because we never
receive this object as a result of subtracting one Date
from another; instead, this
object’s sole purpose is to create month intervals to add or subtract from dates.
In the event that a month interval is added to a date where the day of the month exceeds the
number of days in the result month, the day is set to the final day of the result month.
Therefore, adding one month to 2021-01-31
will return 2021-02-28
.
Importantly, this means that addition and subtraction are not necessarily communitive.
§Example
use date::date;
use date::interval::MonthInterval;
assert_eq!(date! { 2012-04-21 } + MonthInterval::new(3), date! { 2012-07-21 });
assert_eq!(date! { 2021-12-31 } + MonthInterval::new(2), date! { 2022-02-28 });
Implementations§
Trait Implementations§
Source§impl Add<MonthInterval> for Date
impl Add<MonthInterval> for Date
Source§impl Clone for MonthInterval
impl Clone for MonthInterval
Source§fn clone(&self) -> MonthInterval
fn clone(&self) -> MonthInterval
Returns a duplicate 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 MonthInterval
impl Debug for MonthInterval
Source§impl Ord for MonthInterval
impl Ord for MonthInterval
Source§fn cmp(&self, other: &MonthInterval) -> Ordering
fn cmp(&self, other: &MonthInterval) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for MonthInterval
impl PartialEq for MonthInterval
Source§impl PartialOrd for MonthInterval
impl PartialOrd for MonthInterval
Source§impl Sub<MonthInterval> for Date
impl Sub<MonthInterval> for Date
impl Copy for MonthInterval
impl Eq for MonthInterval
impl StructuralPartialEq for MonthInterval
Auto Trait Implementations§
impl Freeze for MonthInterval
impl RefUnwindSafe for MonthInterval
impl Send for MonthInterval
impl Sync for MonthInterval
impl Unpin for MonthInterval
impl UnwindSafe for MonthInterval
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