src/Date.cpp
/*!
    Returns a Date object containing a date \a nyears later than the
    date of this object (or earlier if \a nyears is negative).

    \note If the ending day/month combination does not exist in the
    resulting year (i.e., if the date was Feb 29 and the final year is
    not a leap year), this function will return a date that is the
    latest valid date (that is, Feb 28).

    \sa addDays(), addMonths()
*/
Returns a Date object containing a date \a nyears later than the
date of this object (or earlier if \a nyears is negative).

\note If the ending day/month combination does not exist in the
resulting year , this function will return a date that is the
latest valid date (that is, Feb 28).

\sa addDays(), addMonths()
Returns a Date object containing a date \ a nyears later than the date of this object ( or earlier if \ a nyears is negative ) . \ note If the ending day / month combination does not exist in the resulting year this function will return a date that is the latest valid date ( that is Feb 28 ) . \ sa addDays () addMonths ()
Date Date::addYears(int nyears) const
{
    if (!isValid())
        return Date();
    int old_y = m_dt.year;
    int y = m_dt.year;
    y += nyears;
    if ((old_y > 0 && y <= 0) ||
        (old_y < 0 && y >= 0))
        y += nyears > 0 ? +1 : -1;
    return fixedDate(y, m_dt.mon, m_dt.mday);
}
Date Date :: addYears ( int nyears ) const { if ( ! isValid ( ) ) return Date ( ) ; int old_y = m_dt . year ; int y = m_dt . year ; y += nyears ; if ( ( old_y > 0 && y <= 0 ) || ( old_y < 0 && y >= 0 ) ) y += nyears > 0 ? +1 : -1 ; return fixedDate ( y , m_dt . mon , m_dt . mday ) ; }
Returns a Date object containing a date \a nyears later than the
date of this object (or earlier if \a nyears is negative).
Returns a Date object containing a date \ a nyears later than the date of this object ( or earlier if \ a nyears is negative ) .
// was there a sign change? // yes, adjust the date by +1 or -1 years