fn coerce_md(mut months: i32, from: Date, to: Date) -> (i32, i32) {
        // Months will be in range 1..=12

        months -= 1;

        let days: i32;

        let temp_day = from.day();
        let temp_month = to.month().previous();
        let temp_year = match temp_month {
            Month::December => to.year() - 1,
            _ => to.year(),
        };

        let temp_date = match Date::from_calendar_date(temp_year, temp_month, temp_day) {
            Ok(d) => d,
            Err(_) => {
                // If we have an error then we couldn't get to a real date by adding years and months first.
                // It means we had a long month day (generally 31) and tried to match it to a short month
                // Instead need to add enough days to the from date to get to the first day of the next
                // month before we consider the month or the year move
                // If we have this, the day diff can be calculated directly and we can return straight out
                days = to.day() as i32 + days_in_year_month(from.year(), from.month()) as i32
                    - from.day() as i32
                    + 1;
                return (months, days);
            }
        };

        days = match temp_month {
            Month::December => {
                to.ordinal() as i32 - temp_date.ordinal() as i32 + days_in_year(temp_year) as i32
            }
            _ => to.ordinal() as i32 - temp_date.ordinal() as i32,
        };
        (months, days)
    }
/// Fix months and days to valid ranges
///
/// Months are positive and days are negative
Fix months and days to valid ranges
Months are positive and days are negative
Fix months and days to valid ranges Months are positive and days are negative
fn coerce_md(mut months: i32, from: Date, to: Date) -> (i32, i32) {
        // Months will be in range 1..=12
        months -= 1;
        let days: i32;
        let temp_day = from.day();
        let temp_month = to.month().previous();
        let temp_year = match temp_month {
            Month::December => to.year() - 1,
            _ => to.year(),
        };
        let temp_date = match Date::from_calendar_date(temp_year, temp_month, temp_day) {
            Ok(d) => d,
            Err(_) => {
                // If we have an error then we couldn't get to a real date by adding years and months first.
                // It means we had a long month day (generally 31) and tried to match it to a short month
                // Instead need to add enough days to the from date to get to the first day of the next
                // month before we consider the month or the year move
                // If we have this, the day diff can be calculated directly and we can return straight out
                days = to.day() as i32 + days_in_year_month(from.year(), from.month()) as i32
                    - from.day() as i32
                    + 1;
                return (months, days);
            }
        };
        days = match temp_month {
            Month::December => {
                to.ordinal() as i32 - temp_date.ordinal() as i32 + days_in_year(temp_year) as i32
            }
            _ => to.ordinal() as i32 - temp_date.ordinal() as i32,
        };
        (months, days)
    }
fn coerce_md ( mut months : i32 , from : Date , to : Date ) -> ( i32 , i32 ) { // Months will be in range 1..=12 months -= 1 ; let days : i32 ; let temp_day = from . day ( ) ; let temp_month = to . month ( ) . previous ( ) ; let temp_year = match temp_month { Month :: December => to . year ( ) - 1 , _ => to . year ( ) , } ; let temp_date = match Date :: from_calendar_date ( temp_year , temp_month , temp_day ) { Ok ( d ) => d , Err ( _ ) => { // If we have an error then we couldn't get to a real date by adding years and months first. // It means we had a long month day (generally 31) and tried to match it to a short month // Instead need to add enough days to the from date to get to the first day of the next // month before we consider the month or the year move // If we have this, the day diff can be calculated directly and we can return straight out days = to . day ( ) as i32 + days_in_year_month ( from . year ( ) , from . month ( ) ) as i32 - from . day ( ) as i32 + 1 ; return ( months , days ) ; } } ; days = match temp_month { Month :: December => { to . ordinal ( ) as i32 - temp_date . ordinal ( ) as i32 + days_in_year ( temp_year ) as i32 } _ => to . ordinal ( ) as i32 - temp_date . ordinal ( ) as i32 , } ; ( months , days ) }
Fix months and days to valid ranges
Months are positive and days are negative
Fix months and days to valid ranges Months are positive and days are negative
months
i32
from
Date
to
Date
months
i32
from
Date
to
Date