fn add_ym(&self, date: Date) -> (i32, Month) {
        // Overflowing add on the year and month part
        let mut year = date.year() + self.years;
        let mut month = date.month() as i32 + self.months;

        // Deal with month overflows
        // Months are on the range 1..13, so need to shift by 1 in & out to get logic for end points right
        month -= 1;
        year += month / 12;
        month %= 12;
        if month < 0 {
            month += 12;
            year -= 1;
        }
        month += 1;
        // I'm pretty confident we'll never get an error
        // on the try_from. Used unwrap_or with a default
        // value, so that we remove the chance for panicing
        // code, although this does introduce the risk that
        // I'm wrong and we have a silent error!
        let month = Month::try_from(month as u8).unwrap_or(Month::January);

        (year, month)
    }
/// Add years and months to a date, wrapping month overflows into
/// additional years. Return a tuple of the resultant year and month
Add years and months to a date, wrapping month overflows into
additional years. Return a tuple of the resultant year and month
Add years and months to a date wrapping month overflows into additional years . Return a tuple of the resultant year and month
fn add_ym(&self, date: Date) -> (i32, Month) {
        // Overflowing add on the year and month part
        let mut year = date.year() + self.years;
        let mut month = date.month() as i32 + self.months;
        // Deal with month overflows
        // Months are on the range 1..13, so need to shift by 1 in & out to get logic for end points right
        month -= 1;
        year += month / 12;
        month %= 12;
        if month < 0 {
            month += 12;
            year -= 1;
        }
        month += 1;
        // I'm pretty confident we'll never get an error
        // on the try_from. Used unwrap_or with a default
        // value, so that we remove the chance for panicing
        // code, although this does introduce the risk that
        // I'm wrong and we have a silent error!
        let month = Month::try_from(month as u8).unwrap_or(Month::January);
        (year, month)
    }
fn add_ym ( & self , date : Date ) -> ( i32 , Month ) { // Overflowing add on the year and month part let mut year = date . year ( ) + self . years ; let mut month = date . month ( ) as i32 + self . months ; // Deal with month overflows // Months are on the range 1..13, so need to shift by 1 in & out to get logic for end points right month -= 1 ; year += month / 12 ; month %= 12 ; if month < 0 { month += 12 ; year -= 1 ; } month += 1 ; // I'm pretty confident we'll never get an error // on the try_from. Used unwrap_or with a default // value, so that we remove the chance for panicing // code, although this does introduce the risk that // I'm wrong and we have a silent error! let month = Month :: try_from ( month as u8 ) . unwrap_or ( Month :: January ) ; ( year , month ) }
Add years and months to a date, wrapping month overflows into
additional years.
Add years and months to a date wrapping month overflows into additional years .
&self
date
Date
&self
date
Date