Repository: cakephp/chronos (php)

Issue:
Invalid deprecation error for Date::startOfWeek()
I just updated my installation of Chronos to the latest available version for the project (PHP 7.3, so best I get is 2.4.4), and I got this nonsensical error:
`(new Date($anyDateHere))->addWeeks(1)->startOfWeek()`
throws
`2.5 startOfDay() will be removed in 3.x.`
But this method calls `startOfDay()` implicitly, under the hood, users can't NOT call it.


Pull request description:
Fix deprecations from internals for Date
Fix deprecations for startOfDay/endOfDay being called by startOfWeek/endOfWeek. Because dates don't have times we don't need to modify any time related components and can just return early.

Fixes #453

Patch:
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 @@ trait ModifierTrait
         if ($dt->dayOfWeek !== static::$weekStartsAt) {
             $dt = $dt->previous(static::$weekStartsAt);
         }
+        if ($dt instanceof ChronosDate) {
+            return $dt;
+        }
 
         return $dt->startOfDay();
     }
@@ -1066,6 +1069,9 @@ trait ModifierTrait
         if ($dt->dayOfWeek !== static::$weekEndsAt) {
             $dt = $dt->next(static::$weekEndsAt);
         }
+        if ($dt instanceof ChronosDate) {
+            return $dt;
+        }
 
         return $dt->endOfDay();
     }


Test patch:
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 @@ class AddTest extends TestCase
         $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 @@ class AddTest extends TestCase
      */
     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);
     }
 
     /**