mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-30 14:32:19 +00:00
Move doc comments from method to trait (for consistency)
This commit is contained in:
parent
483da3b834
commit
78230395a6
@ -1865,54 +1865,54 @@ impl AddAssign<OldDuration> for NaiveDate {
|
||||
}
|
||||
}
|
||||
|
||||
/// An addition of months to `NaiveDate` clamped to valid days in resulting month.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the resulting date would be out of range.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use chrono::{NaiveDate, Months};
|
||||
///
|
||||
/// let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
|
||||
///
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) + Months::new(1), from_ymd(2014, 2, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) + Months::new(11), from_ymd(2014, 12, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) + Months::new(12), from_ymd(2015, 1, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) + Months::new(13), from_ymd(2015, 2, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 31) + Months::new(1), from_ymd(2014, 2, 28));
|
||||
/// assert_eq!(from_ymd(2020, 1, 31) + Months::new(1), from_ymd(2020, 2, 29));
|
||||
/// ```
|
||||
impl Add<Months> for NaiveDate {
|
||||
type Output = NaiveDate;
|
||||
|
||||
/// An addition of months to `NaiveDate` clamped to valid days in resulting month.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the resulting date would be out of range.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use chrono::{NaiveDate, Months};
|
||||
///
|
||||
/// let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
|
||||
///
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) + Months::new(1), from_ymd(2014, 2, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) + Months::new(11), from_ymd(2014, 12, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) + Months::new(12), from_ymd(2015, 1, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) + Months::new(13), from_ymd(2015, 2, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 31) + Months::new(1), from_ymd(2014, 2, 28));
|
||||
/// assert_eq!(from_ymd(2020, 1, 31) + Months::new(1), from_ymd(2020, 2, 29));
|
||||
/// ```
|
||||
fn add(self, months: Months) -> Self::Output {
|
||||
self.checked_add_months(months).expect("`NaiveDate + Months` out of range")
|
||||
}
|
||||
}
|
||||
|
||||
/// A subtraction of Months from `NaiveDate` clamped to valid days in resulting month.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the resulting date would be out of range.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use chrono::{NaiveDate, Months};
|
||||
///
|
||||
/// let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
|
||||
///
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) - Months::new(11), from_ymd(2013, 2, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) - Months::new(12), from_ymd(2013, 1, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) - Months::new(13), from_ymd(2012, 12, 1));
|
||||
/// ```
|
||||
impl Sub<Months> for NaiveDate {
|
||||
type Output = NaiveDate;
|
||||
|
||||
/// A subtraction of Months from `NaiveDate` clamped to valid days in resulting month.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the resulting date would be out of range.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use chrono::{NaiveDate, Months};
|
||||
///
|
||||
/// let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
|
||||
///
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) - Months::new(11), from_ymd(2013, 2, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) - Months::new(12), from_ymd(2013, 1, 1));
|
||||
/// assert_eq!(from_ymd(2014, 1, 1) - Months::new(13), from_ymd(2012, 12, 1));
|
||||
/// ```
|
||||
fn sub(self, months: Months) -> Self::Output {
|
||||
self.checked_sub_months(months).expect("`NaiveDate - Months` out of range")
|
||||
}
|
||||
|
@ -1628,45 +1628,45 @@ impl Add<FixedOffset> for NaiveDateTime {
|
||||
}
|
||||
}
|
||||
|
||||
/// An addition of months to `NaiveDateTime` clamped to valid days in resulting month.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the resulting date would be out of range.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use chrono::{Months, NaiveDate};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 1).unwrap().and_hms_opt(1, 0, 0).unwrap() + Months::new(1),
|
||||
/// NaiveDate::from_ymd_opt(2014, 2, 1).unwrap().and_hms_opt(1, 0, 0).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 1).unwrap().and_hms_opt(0, 2, 0).unwrap() + Months::new(11),
|
||||
/// NaiveDate::from_ymd_opt(2014, 12, 1).unwrap().and_hms_opt(0, 2, 0).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 1).unwrap().and_hms_opt(0, 0, 3).unwrap() + Months::new(12),
|
||||
/// NaiveDate::from_ymd_opt(2015, 1, 1).unwrap().and_hms_opt(0, 0, 3).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 1).unwrap().and_hms_opt(0, 0, 4).unwrap() + Months::new(13),
|
||||
/// NaiveDate::from_ymd_opt(2015, 2, 1).unwrap().and_hms_opt(0, 0, 4).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 31).unwrap().and_hms_opt(0, 5, 0).unwrap() + Months::new(1),
|
||||
/// NaiveDate::from_ymd_opt(2014, 2, 28).unwrap().and_hms_opt(0, 5, 0).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2020, 1, 31).unwrap().and_hms_opt(6, 0, 0).unwrap() + Months::new(1),
|
||||
/// NaiveDate::from_ymd_opt(2020, 2, 29).unwrap().and_hms_opt(6, 0, 0).unwrap()
|
||||
/// );
|
||||
/// ```
|
||||
impl Add<Months> for NaiveDateTime {
|
||||
type Output = NaiveDateTime;
|
||||
|
||||
/// An addition of months to `NaiveDateTime` clamped to valid days in resulting month.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the resulting date would be out of range.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use chrono::{Months, NaiveDate};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 1).unwrap().and_hms_opt(1, 0, 0).unwrap() + Months::new(1),
|
||||
/// NaiveDate::from_ymd_opt(2014, 2, 1).unwrap().and_hms_opt(1, 0, 0).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 1).unwrap().and_hms_opt(0, 2, 0).unwrap() + Months::new(11),
|
||||
/// NaiveDate::from_ymd_opt(2014, 12, 1).unwrap().and_hms_opt(0, 2, 0).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 1).unwrap().and_hms_opt(0, 0, 3).unwrap() + Months::new(12),
|
||||
/// NaiveDate::from_ymd_opt(2015, 1, 1).unwrap().and_hms_opt(0, 0, 3).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 1).unwrap().and_hms_opt(0, 0, 4).unwrap() + Months::new(13),
|
||||
/// NaiveDate::from_ymd_opt(2015, 2, 1).unwrap().and_hms_opt(0, 0, 4).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2014, 1, 31).unwrap().and_hms_opt(0, 5, 0).unwrap() + Months::new(1),
|
||||
/// NaiveDate::from_ymd_opt(2014, 2, 28).unwrap().and_hms_opt(0, 5, 0).unwrap()
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// NaiveDate::from_ymd_opt(2020, 1, 31).unwrap().and_hms_opt(6, 0, 0).unwrap() + Months::new(1),
|
||||
/// NaiveDate::from_ymd_opt(2020, 2, 29).unwrap().and_hms_opt(6, 0, 0).unwrap()
|
||||
/// );
|
||||
/// ```
|
||||
fn add(self, rhs: Months) -> Self::Output {
|
||||
self.checked_add_months(rhs).expect("`NaiveDateTime + Months` out of range")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user