Skip to content

Commit

Permalink
Merge pull request #329 from cakephp/fix-negatives
Browse files Browse the repository at this point in the history
Fix passing negative value to subUnit() helpers
  • Loading branch information
othercorey authored Oct 21, 2022
2 parents 03f1212 + 1f1b420 commit 1075511
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/Traits/ModifierTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function microsecond(int $value): ChronosInterface
public function addYears(int $value): ChronosInterface
{
$month = $this->month;
$date = $this->modify($value . ' year');
$date = $this->modify($value . ' years');

if ($date->month !== $month) {
return $date->modify('last day of previous month');
Expand Down Expand Up @@ -309,7 +309,7 @@ public function addYear(int $value = 1): ChronosInterface
*/
public function subYears(int $value): ChronosInterface
{
return $this->addYears(-1 * $value);
return $this->addYears(-$value);
}

/**
Expand All @@ -322,7 +322,7 @@ public function subYears(int $value): ChronosInterface
*/
public function subYear(int $value = 1): ChronosInterface
{
return $this->subYears($value);
return $this->addYears(-$value);
}

/**
Expand Down Expand Up @@ -406,7 +406,7 @@ public function subYearWithOverflow(int $value = 1): ChronosInterface
public function addMonths(int $value): ChronosInterface
{
$day = $this->day;
$date = $this->modify($value . ' month');
$date = $this->modify($value . ' months');

if ($date->day !== $day) {
return $date->modify('last day of previous month');
Expand Down Expand Up @@ -438,7 +438,7 @@ public function addMonth(int $value = 1): ChronosInterface
*/
public function subMonth(int $value = 1): ChronosInterface
{
return $this->subMonths($value);
return $this->addMonths(-$value);
}

/**
Expand All @@ -451,7 +451,7 @@ public function subMonth(int $value = 1): ChronosInterface
*/
public function subMonths(int $value): ChronosInterface
{
return $this->addMonths(-1 * $value);
return $this->addMonths(-$value);
}

/**
Expand All @@ -471,7 +471,7 @@ public function subMonths(int $value): ChronosInterface
*/
public function addMonthsWithOverflow(int $value): ChronosInterface
{
return $this->modify($value . ' month');
return $this->modify($value . ' months');
}

/**
Expand All @@ -484,7 +484,7 @@ public function addMonthsWithOverflow(int $value): ChronosInterface
*/
public function addMonthWithOverflow(int $value = 1): ChronosInterface
{
return $this->modify($value . ' month');
return $this->modify($value . ' months');
}

/**
Expand Down Expand Up @@ -522,7 +522,7 @@ public function subMonthWithOverflow(int $value = 1): ChronosInterface
*/
public function addDays(int $value): ChronosInterface
{
return $this->modify("$value day");
return $this->modify("$value days");
}

/**
Expand All @@ -533,7 +533,7 @@ public function addDays(int $value): ChronosInterface
*/
public function addDay(int $value = 1): ChronosInterface
{
return $this->modify("$value day");
return $this->modify("$value days");
}

/**
Expand All @@ -544,7 +544,7 @@ public function addDay(int $value = 1): ChronosInterface
*/
public function subDay(int $value = 1): ChronosInterface
{
return $this->modify("-$value day");
return $this->addDays(-$value);
}

/**
Expand All @@ -555,7 +555,7 @@ public function subDay(int $value = 1): ChronosInterface
*/
public function subDays(int $value): ChronosInterface
{
return $this->modify("-$value day");
return $this->addDays(-$value);
}

/**
Expand All @@ -567,7 +567,7 @@ public function subDays(int $value): ChronosInterface
*/
public function addWeekdays(int $value): ChronosInterface
{
return $this->modify((int)$value . ' weekdays ' . $this->format('H:i:s'));
return $this->modify($value . ' weekdays, ' . $this->format('H:i:s'));
}

/**
Expand All @@ -589,7 +589,7 @@ public function addWeekday(int $value = 1): ChronosInterface
*/
public function subWeekdays(int $value): ChronosInterface
{
return $this->modify("$value weekdays ago, " . $this->format('H:i:s'));
return $this->addWeekdays(-$value);
}

/**
Expand All @@ -600,7 +600,7 @@ public function subWeekdays(int $value): ChronosInterface
*/
public function subWeekday(int $value = 1): ChronosInterface
{
return $this->subWeekdays($value);
return $this->addWeekdays(-$value);
}

/**
Expand Down Expand Up @@ -634,7 +634,7 @@ public function addWeek(int $value = 1): ChronosInterface
*/
public function subWeek(int $value = 1): ChronosInterface
{
return $this->modify("-$value week");
return $this->addWeeks(-$value);
}

/**
Expand All @@ -645,7 +645,7 @@ public function subWeek(int $value = 1): ChronosInterface
*/
public function subWeeks(int $value): ChronosInterface
{
return $this->modify("-$value week");
return $this->addWeeks(-$value);
}

/**
Expand Down Expand Up @@ -679,7 +679,7 @@ public function addHour(int $value = 1): ChronosInterface
*/
public function subHour(int $value = 1): ChronosInterface
{
return $this->modify("-$value hour");
return $this->addHours(-$value);
}

/**
Expand All @@ -690,7 +690,7 @@ public function subHour(int $value = 1): ChronosInterface
*/
public function subHours(int $value): ChronosInterface
{
return $this->modify("-$value hour");
return $this->addHours(-$value);
}

/**
Expand Down Expand Up @@ -724,7 +724,7 @@ public function addMinute(int $value = 1): ChronosInterface
*/
public function subMinute(int $value = 1): ChronosInterface
{
return $this->modify("-$value minute");
return $this->addMinutes(-$value);
}

/**
Expand All @@ -735,7 +735,7 @@ public function subMinute(int $value = 1): ChronosInterface
*/
public function subMinutes(int $value): ChronosInterface
{
return $this->modify("-$value minute");
return $this->addMinutes(-$value);
}

/**
Expand Down Expand Up @@ -769,7 +769,7 @@ public function addSecond(int $value = 1): ChronosInterface
*/
public function subSecond(int $value = 1): ChronosInterface
{
return $this->modify("-$value second");
return $this->addSeconds(-$value);
}

/**
Expand All @@ -780,7 +780,7 @@ public function subSecond(int $value = 1): ChronosInterface
*/
public function subSeconds(int $value): ChronosInterface
{
return $this->modify("-$value second");
return $this->addSeconds(-$value);
}

/**
Expand Down

0 comments on commit 1075511

Please sign in to comment.