public function subMonths(int $months = 1): Jalalian
{
Assertion::greaterOrEqualThan($months, 1);
$years = (int)($months / 12);
$newDate = clone $this;
if($years > 0)
$newDate = $this->subYears($years);
$rem = $months % 12;
$targetMonth = $newDate->getMonth() - $rem;
if($targetMonth > 0) {
$day = $newDate->getDay();
$targetMonthDays = $newDate->getDaysOf($targetMonth);
$targetDay = $day <= $targetMonthDays ? $day : $targetMonthDays;
return new static(
$newDate->getYear(),
$targetMonth,
$targetDay,
$newDate->getHour(),
$newDate->getMinute(),
$newDate->getSecond(),
$newDate->getTimezone()
);
} else {
$targetMonth = 12 - abs($targetMonth);
$day = $newDate->getDay();
$targetMonthDays = $newDate->getDaysOf($targetMonth);
$targetDay = $day <= $targetMonthDays ? $day : $targetMonthDays;
return new static(
$newDate->getYear() - 1,
$targetMonth,
$targetDay,
$newDate->getHour(),
$newDate->getMinute(),
$newDate->getSecond(),
$newDate->getTimezone()
);
}
}