src/YearMonth.php
public function plusMonths(int $months) : YearMonth
    {
        if ($months === 0) {
            return $this;
        }

        $month = $this->month + $months - 1;

        $yearDiff = Math::floorDiv($month, 12);
        $month = Math::floorMod($month, 12) + 1;

        $year = $this->year + $yearDiff;

        return new YearMonth($year, $month);
    }
public function plusMonths(int $months) : YearMonth
    {
        if ($months === 0) {
            return $this;
        }

        $month = $this->month + $months - 1;

        $yearDiff = Math::floorDiv($month, 12);
        $month = Math::floorMod($month, 12) + 1;

        $year = $this->year + $yearDiff;

        return new YearMonth($year, $month);
    }
public function plusMonths ( int $ months ) : YearMonth { if ( $ months === 0 ) { return $ this ; } $ month = $ this -> month + $ months - 1 ; $ yearDiff = Math :: floorDiv ( $ month , 12 ) ; $ month = Math :: floorMod ( $ month , 12 ) + 1 ; $ year = $ this -> year + $ yearDiff ; return new YearMonth ( $ year , $ month ) ; }
Returns a copy of this YearMonth with the specified period in months added.

@param int $months

@return YearMonth
Returns a copy of this YearMonth with the specified period in months added .