Skip to content

Commit

Permalink
Merge pull request #459 from cakephp/fix-453
Browse files Browse the repository at this point in the history
Fix deprecations from internals for Date
  • Loading branch information
dereuromark authored Jul 24, 2024
2 parents 7d66414 + 2cbf986 commit 0dc2ee1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Traits/ModifierTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,9 @@ public function startOfWeek(): ChronosInterface
if ($dt->dayOfWeek !== static::$weekStartsAt) {
$dt = $dt->previous(static::$weekStartsAt);
}
if ($dt instanceof ChronosDate) {
return $dt;
}

return $dt->startOfDay();
}
Expand All @@ -1066,6 +1069,9 @@ public function endOfWeek(): ChronosInterface
if ($dt->dayOfWeek !== static::$weekEndsAt) {
$dt = $dt->next(static::$weekEndsAt);
}
if ($dt instanceof ChronosDate) {
return $dt;
}

return $dt->endOfDay();
}
Expand Down
18 changes: 18 additions & 0 deletions tests/TestCase/Date/AddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,22 @@ public function testAddWeekdays($class)
$this->assertSame(2, $class::create(1975, 5, 31)->addWeekdays(1)->day);
$this->assertSame(30, $class::create(1975, 5, 31)->addWeekdays(-1)->day);
}

/**
* @dataProvider dateClassProvider
* @return void
*/
public function testAddWeeksStartOfWeek($class)
{
$this->assertSame(8, (new $class('2024-7-2'))->addWeeks(1)->startOfWeek()->day);
}

/**
* @dataProvider dateClassProvider
* @return void
*/
public function testAddWeeksEndOfWeek($class)
{
$this->assertSame(14, (new $class('2024-7-2'))->addWeeks(1)->endOfWeek()->day);
}
}
4 changes: 2 additions & 2 deletions tests/TestCase/DateTime/AddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ public function testAddWeek($class)
*/
public function testAddWeeksStartOfWeek($class)
{
$this->assertSame(5, (new $class(2024, 7, 2,))->addWeeks(1)->startOfWeek()->day);
$this->assertSame(5, (new $class(2024, 7, 2))->addWeeks(1)->startOfWeek()->day);

$this->assertSame(14, $class::createFromDate(2024, 7, 2,)->addWeeks(1)->endOfWeek()->day);
$this->assertSame(14, $class::createFromDate(2024, 7, 2)->addWeeks(1)->endOfWeek()->day);
}

/**
Expand Down

0 comments on commit 0dc2ee1

Please sign in to comment.