Swat/SwatDate.php
public function addStrictMonths($months)
    {
        $months = (int) $months;

        $years = (int) ($months / 12);
        $months = $months % 12;

        $year = $this->getYear() + $years;
        $month = $this->getMonth() + $months;

        if ($month < 1) {
            $year -= 1;
            $month += 12;
        } elseif ($month > 12) {
            $year += 1;
            $month -= 12;
        }

        $success = $this->setDate($year, $month, $this->getDay());

        if (!$success) {
            throw new Exception(
                sprintf(
                    'Can not add %d whole months to %s.',
                    $months,
                    $this->format('c')
                )
            );
        }

        return $this;
    }
public function addStrictMonths($months)
    {
        $months = (int) $months;

        $years = (int) ($months / 12);
        $months = $months % 12;

        $year = $this->getYear() + $years;
        $month = $this->getMonth() + $months;

        if ($month < 1) {
            $year -= 1;
            $month += 12;
        } elseif ($month > 12) {
            $year += 1;
            $month -= 12;
        }

        $success = $this->setDate($year, $month, $this->getDay());

        if (!$success) {
            throw new Exception(
                sprintf(
                    'Can not add %d whole months to %s.',
                    $months,
                    $this->format('c')
                )
            );
        }

        return $this;
    }
public function addStrictMonths ( $ months ) { $ months = ( int ) $ months ; $ years = ( int ) ( $ months / 12 ) ; $ months = $ months % 12 ; $ year = $ this -> getYear ( ) + $ years ; $ month = $ this -> getMonth ( ) + $ months ; if ( $ month < 1 ) { $ year -= 1 ; $ month += 12 ; } elseif ( $ month > 12 ) { $ year += 1 ; $ month -= 12 ; } $ success = $ this -> setDate ( $ year , $ month , $ this -> getDay ( ) ) ; if ( ! $ success ) { throw new Exception ( sprintf ( 'Can not add %d whole months to %s.' , $ months , $ this -> format ( 'c' ) ) ) ; } return $ this ; }
Adds months to this date without affecting the day of the month

This differs from {@link SwatDate::addMonths()} in how dates at the end
of a month are handled. In SwatDate::addMonths(), if one month is added
to January 31, the resulting date will be March 2 or 3 depending on
if it is a leap year.

In this method, if one month is added to January 31, an exception is
thrown.

@param integer $months the number of months to add.

@return SwatDate this object.

@throws Exception if the resulting date is invalid (i.e. February 30) an
exception is thrown.
Adds months to this date without affecting the day of the month