diff --git a/src/Traits/ModifierTrait.php b/src/Traits/ModifierTrait.php index 8d1797d..effe09a 100644 --- a/src/Traits/ModifierTrait.php +++ b/src/Traits/ModifierTrait.php @@ -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(); } @@ -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(); } diff --git a/tests/TestCase/Date/AddTest.php b/tests/TestCase/Date/AddTest.php index 9da9ccf..e6389b3 100644 --- a/tests/TestCase/Date/AddTest.php +++ b/tests/TestCase/Date/AddTest.php @@ -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); + } } diff --git a/tests/TestCase/DateTime/AddTest.php b/tests/TestCase/DateTime/AddTest.php index 61fddb3..8e06fed 100644 --- a/tests/TestCase/DateTime/AddTest.php +++ b/tests/TestCase/DateTime/AddTest.php @@ -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); } /**