From e319be917505428453ac45a33f0a066bebec48a9 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 14 Oct 2023 23:42:42 -0500 Subject: [PATCH] Add microseconds to Chronos::endOfDay() --- src/ChronosInterface.php | 28 ++++++++++++---------- src/Traits/ModifierTrait.php | 28 ++++++++++++---------- tests/TestCase/DateTime/StartEndOfTest.php | 6 ++++- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/ChronosInterface.php b/src/ChronosInterface.php index fa7a4738..f7b80b64 100644 --- a/src/ChronosInterface.php +++ b/src/ChronosInterface.php @@ -1153,84 +1153,86 @@ public function secondsSinceMidnight(): int; public function secondsUntilEndOfDay(): int; /** - * Resets the time to 00:00:00 + * Sets the time to 00:00:00 * * @return static */ public function startOfDay(): self; /** - * Resets the time to 23:59:59 + * Sets the time to end of day - either + * 23:59:59 or 23:59:59.999999 if `$microseconds` is true. * + * @param bool $microseconds Whether to set microseconds * @return static */ - public function endOfDay(): self; + public function endOfDay(bool $microseconds = false): self; /** - * Resets the date to the first day of the month and the time to 00:00:00 + * Sets the date to the first day of the month and the time to 00:00:00 * * @return static */ public function startOfMonth(): self; /** - * Resets the date to end of the month and time to 23:59:59 + * Sets the date to end of the month and time to 23:59:59 * * @return static */ public function endOfMonth(): self; /** - * Resets the date to the first day of the year and the time to 00:00:00 + * Sets the date to the first day of the year and the time to 00:00:00 * * @return static */ public function startOfYear(): self; /** - * Resets the date to end of the year and time to 23:59:59 + * Sets the date to end of the year and time to 23:59:59 * * @return static */ public function endOfYear(): self; /** - * Resets the date to the first day of the decade and the time to 00:00:00 + * Sets the date to the first day of the decade and the time to 00:00:00 * * @return static */ public function startOfDecade(): self; /** - * Resets the date to end of the decade and time to 23:59:59 + * Sets the date to end of the decade and time to 23:59:59 * * @return static */ public function endOfDecade(): self; /** - * Resets the date to the first day of the century and the time to 00:00:00 + * Sets the date to the first day of the century and the time to 00:00:00 * * @return static */ public function startOfCentury(): self; /** - * Resets the date to end of the century and time to 23:59:59 + * Sets the date to end of the century and time to 23:59:59 * * @return static */ public function endOfCentury(): self; /** - * Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00 + * Sets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00 * * @return static */ public function startOfWeek(): self; /** - * Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59 + * Sets the date to end of week (defined in $weekEndsAt) and time to 23:59:59 * * @return static */ diff --git a/src/Traits/ModifierTrait.php b/src/Traits/ModifierTrait.php index c2624d3d..8c1049d7 100644 --- a/src/Traits/ModifierTrait.php +++ b/src/Traits/ModifierTrait.php @@ -894,7 +894,7 @@ public function subSeconds(int $value): ChronosInterface } /** - * Resets the time to 00:00:00 + * Sets the time to 00:00:00 * * @return static */ @@ -908,11 +908,13 @@ public function startOfDay(): ChronosInterface } /** - * Resets the time to 23:59:59 + * Sets the time to end of day - either + * 23:59:59 or 23:59:59.999999 if `$microseconds` is true. * + * @param bool $microseconds Whether to set microseconds * @return static */ - public function endOfDay(): ChronosInterface + public function endOfDay(bool $microseconds = false): ChronosInterface { if (static::class === ChronosDate::class) { trigger_error('2.5 endOfDay() will be removed in 3.x.', E_USER_DEPRECATED); @@ -922,7 +924,7 @@ public function endOfDay(): ChronosInterface } /** - * Resets the date to the first day of the month and the time to 00:00:00 + * Sets the date to the first day of the month and the time to 00:00:00 * * @return static */ @@ -936,7 +938,7 @@ public function startOfMonth(): ChronosInterface } /** - * Resets the date to end of the month and time to 23:59:59 + * Sets the date to end of the month and time to 23:59:59 * * @return static */ @@ -950,7 +952,7 @@ public function endOfMonth(): ChronosInterface } /** - * Resets the date to the first day of the year and the time to 00:00:00 + * Sets the date to the first day of the year and the time to 00:00:00 * * @return static */ @@ -964,7 +966,7 @@ public function startOfYear(): ChronosInterface } /** - * Resets the date to end of the year and time to 23:59:59 + * Sets the date to end of the year and time to 23:59:59 * * @return static */ @@ -978,7 +980,7 @@ public function endOfYear(): ChronosInterface } /** - * Resets the date to the first day of the decade and the time to 00:00:00 + * Sets the date to the first day of the decade and the time to 00:00:00 * * @return static */ @@ -990,7 +992,7 @@ public function startOfDecade(): ChronosInterface } /** - * Resets the date to end of the decade and time to 23:59:59 + * Sets the date to end of the decade and time to 23:59:59 * * @return static */ @@ -1002,7 +1004,7 @@ public function endOfDecade(): ChronosInterface } /** - * Resets the date to the first day of the century and the time to 00:00:00 + * Sets the date to the first day of the century and the time to 00:00:00 * * @return static */ @@ -1016,7 +1018,7 @@ public function startOfCentury(): ChronosInterface } /** - * Resets the date to end of the century and time to 23:59:59 + * Sets the date to end of the century and time to 23:59:59 * * @return static */ @@ -1035,7 +1037,7 @@ public function endOfCentury(): ChronosInterface } /** - * Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00 + * Sets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00 * * @return static */ @@ -1050,7 +1052,7 @@ public function startOfWeek(): ChronosInterface } /** - * Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59 + * Sets the date to end of week (defined in $weekEndsAt) and time to 23:59:59 * * @return static */ diff --git a/tests/TestCase/DateTime/StartEndOfTest.php b/tests/TestCase/DateTime/StartEndOfTest.php index ec9e683f..f7d88198 100644 --- a/tests/TestCase/DateTime/StartEndOfTest.php +++ b/tests/TestCase/DateTime/StartEndOfTest.php @@ -40,7 +40,11 @@ public function testEndOfDay($class) $now = $class::now(); $dt = $now->endOfDay(); $this->assertTrue($dt instanceof $class); - $this->assertDateTime($dt, $dt->year, $dt->month, $dt->day, 23, 59, 59); + $this->assertDateTime($dt, $dt->year, $dt->month, $dt->day, 23, 59, 59, 0); + + $dt = $now->endOfDay(true); + $this->assertTrue($dt instanceof $class); + $this->assertDateTime($dt, $dt->year, $dt->month, $dt->day, 23, 59, 59, 999999); } /**