morilog / jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in php appliations, based on Jalali (Shamsi) DateTime class.
MIT License
860 stars 110 forks source link

The addMonths method in Jalalian class has bug !!! #50

Closed MostafaRDE closed 5 years ago

MostafaRDE commented 5 years ago

`Assertion::greaterOrEqualThan($months, 1);

    $years = (int) ($months / 12);
    $date = $years > 0 ? $this->addYears($years) : clone $this;

    $months = ($months % 12) + $date->getMonth();
    $days = 0;

    for ($i = $date->getMonth() + 1; $i <= $months; $i++) {
        $days += $date->getDaysOf($i); **// Bug here**
        if ($i === 12) {
            $i = 1;
            $months = $months - 12;
        }
    }

    return $date->addDays($days);`

Sometimes maybe month is 12, so when month total with 1 digit, reporting exception: Provided "13" is neither greater than or equal to "1" nor less than or equal to "12".

ahmadmrj commented 5 years ago

I faced with this problem too!

morilog commented 5 years ago

This issue fixed at v3.0.12