Skip to content

Commit

Permalink
Use constants instead. (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee authored Jun 11, 2024
1 parent de979c8 commit fb0c886
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Psl/DateTime/DateTimeConvenienceMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ public function plusMonths(int $months): static
return $this->minusMonths(-$months);
}

$plus_years = Math\div($months, 12);
$months_left = $months - ($plus_years * 12);
$plus_years = Math\div($months, MONTHS_PER_YEAR);
$months_left = $months - ($plus_years * MONTHS_PER_YEAR);
$target_month = $this->getMonth() + $months_left;

if ($target_month > 12) {
$plus_years++;
$target_month = $target_month - 12;
$target_month = $target_month - MONTHS_PER_YEAR;
}

$target_month_enum = Month::from($target_month);
Expand Down Expand Up @@ -442,13 +442,13 @@ public function minusMonths(int $months): static
return $this->plusMonths(-$months);
}

$minus_years = Math\div($months, 12);
$months_left = $months - ($minus_years * 12);
$minus_years = Math\div($months, MONTHS_PER_YEAR);
$months_left = $months - ($minus_years * MONTHS_PER_YEAR);
$target_month = $this->getMonth() - $months_left;

if ($target_month <= 0) {
$minus_years++;
$target_month = 12 - Math\abs($target_month);
$target_month = MONTHS_PER_YEAR - Math\abs($target_month);
}

$target_month_enum = Month::from($target_month);
Expand Down

0 comments on commit fb0c886

Please sign in to comment.