Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start deprecations for 2.next #344

Merged
merged 5 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Traits/ComparisonTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public function isTomorrow(): bool
*/
public function isNextWeek(): bool
{
return $this->format('W o') === static::now($this->tz)->addWeek()->format('W o');
return $this->format('W o') === static::now($this->tz)->addWeeks(1)->format('W o');
}

/**
Expand All @@ -324,7 +324,7 @@ public function isNextWeek(): bool
*/
public function isLastWeek(): bool
{
return $this->format('W o') === static::now($this->tz)->subWeek()->format('W o');
return $this->format('W o') === static::now($this->tz)->subWeeks(1)->format('W o');
}

/**
Expand All @@ -334,7 +334,7 @@ public function isLastWeek(): bool
*/
public function isNextMonth(): bool
{
return $this->format('m Y') === static::now($this->tz)->addMonth()->format('m Y');
return $this->format('m Y') === static::now($this->tz)->addMonths(1)->format('m Y');
}

/**
Expand All @@ -344,7 +344,7 @@ public function isNextMonth(): bool
*/
public function isLastMonth(): bool
{
return $this->format('m Y') === static::now($this->tz)->subMonth()->format('m Y');
return $this->format('m Y') === static::now($this->tz)->subMonths(1)->format('m Y');
}

/**
Expand All @@ -354,7 +354,7 @@ public function isLastMonth(): bool
*/
public function isNextYear(): bool
{
return $this->year === static::now($this->tz)->addYear()->year;
return $this->year === static::now($this->tz)->addYears(1)->year;
}

/**
Expand All @@ -364,7 +364,7 @@ public function isNextYear(): bool
*/
public function isLastYear(): bool
{
return $this->year === static::now($this->tz)->subYear()->year;
return $this->year === static::now($this->tz)->subYears(1)->year;
}

/**
Expand Down
42 changes: 42 additions & 0 deletions src/Traits/ModifierTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ public function addYears(int $value): ChronosInterface
*/
public function addYear(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - addYear() is deprecated. Use addYears() instead.', E_USER_DEPRECATED);

return $this->addYears($value);
}

Expand All @@ -322,6 +324,8 @@ public function subYears(int $value): ChronosInterface
*/
public function subYear(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - subYear() is deprecated. Use subYears() instead.', E_USER_DEPRECATED);

return $this->addYears(-$value);
}

Expand Down Expand Up @@ -355,6 +359,8 @@ public function addYearsWithOverflow(int $value): ChronosInterface
*/
public function addYearWithOverflow(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - addYearWithOverflow() is deprecated.', E_USER_DEPRECATED);

return $this->addYearsWithOverflow($value);
}

Expand Down Expand Up @@ -425,6 +431,8 @@ public function addMonths(int $value): ChronosInterface
*/
public function addMonth(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - addMonth() is deprecated. Use addMonths() instead.', E_USER_DEPRECATED);

return $this->addMonths($value);
}

Expand All @@ -438,6 +446,8 @@ public function addMonth(int $value = 1): ChronosInterface
*/
public function subMonth(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - subMonth() is deprecated. Use subMonths() instead.', E_USER_DEPRECATED);

return $this->addMonths(-$value);
}

Expand Down Expand Up @@ -484,6 +494,11 @@ public function addMonthsWithOverflow(int $value): ChronosInterface
*/
public function addMonthWithOverflow(int $value = 1): ChronosInterface
{
trigger_error(
'Since 2.4 - addMonthWithOverflow() is deprecated. Use addMonthsWithOverflow() instead.',
E_USER_DEPRECATED
);

return $this->modify($value . ' months');
}

Expand All @@ -510,6 +525,11 @@ public function subMonthsWithOverflow(int $value): ChronosInterface
*/
public function subMonthWithOverflow(int $value = 1): ChronosInterface
{
trigger_error(
'Since 2.4 - subMonthWithOverflow() is deprecated. Use subMonthsWithOverflow() instead.',
E_USER_DEPRECATED
);

return $this->subMonthsWithOverflow($value);
}

Expand All @@ -533,6 +553,8 @@ public function addDays(int $value): ChronosInterface
*/
public function addDay(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - addDay() is deprecated. Use addDays() instead.', E_USER_DEPRECATED);

return $this->modify("$value days");
}

Expand All @@ -544,6 +566,8 @@ public function addDay(int $value = 1): ChronosInterface
*/
public function subDay(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - subDay() is deprecated. Use subDays() instead.', E_USER_DEPRECATED);

return $this->addDays(-$value);
}

Expand Down Expand Up @@ -578,6 +602,8 @@ public function addWeekdays(int $value): ChronosInterface
*/
public function addWeekday(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - addWeekday() is deprecated. Use addWeekdays() instead.', E_USER_DEPRECATED);

return $this->addWeekdays($value);
}

Expand Down Expand Up @@ -623,6 +649,8 @@ public function addWeeks(int $value): ChronosInterface
*/
public function addWeek(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - addWeek() is deprecated. Use addWeeks() instead.', E_USER_DEPRECATED);

return $this->modify("$value week");
}

Expand All @@ -634,6 +662,8 @@ public function addWeek(int $value = 1): ChronosInterface
*/
public function subWeek(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - subWeek() is deprecated. Use subWeeks() instead.', E_USER_DEPRECATED);

return $this->addWeeks(-$value);
}

Expand Down Expand Up @@ -668,6 +698,8 @@ public function addHours(int $value): ChronosInterface
*/
public function addHour(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - addHour() is deprecated. Use addHours() instead.', E_USER_DEPRECATED);

return $this->modify("$value hour");
}

Expand All @@ -679,6 +711,8 @@ public function addHour(int $value = 1): ChronosInterface
*/
public function subHour(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - subHour() is deprecated. Use subHours() instead.', E_USER_DEPRECATED);

return $this->addHours(-$value);
}

Expand Down Expand Up @@ -713,6 +747,8 @@ public function addMinutes(int $value): ChronosInterface
*/
public function addMinute(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - addMinute() is deprecated. Use addMinutes() instead.', E_USER_DEPRECATED);

return $this->modify("$value minute");
}

Expand All @@ -724,6 +760,8 @@ public function addMinute(int $value = 1): ChronosInterface
*/
public function subMinute(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - subMinute() is deprecated. Use subMinutes() instead.', E_USER_DEPRECATED);

return $this->addMinutes(-$value);
}

Expand Down Expand Up @@ -758,6 +796,8 @@ public function addSeconds(int $value): ChronosInterface
*/
public function addSecond(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - addSecond() is deprecated. Use addSeconds() instead.', E_USER_DEPRECATED);

return $this->modify("$value second");
}

Expand All @@ -769,6 +809,8 @@ public function addSecond(int $value = 1): ChronosInterface
*/
public function subSecond(int $value = 1): ChronosInterface
{
trigger_error('Since 2.4 - subSecond() is deprecated. Use subSeconds() instead.', E_USER_DEPRECATED);

return $this->addSeconds(-$value);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Date/IsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function testIsTodayOtherTimezone($class)
*/
public function testIsTodayFalseWithYesterday($class)
{
$this->assertFalse($class::now()->subDay()->endOfDay()->isToday());
$this->assertFalse($class::now()->subDays(1)->endOfDay()->isToday());
}
}
Loading