diff --git a/src/ChronosTime.php b/src/ChronosTime.php index 7c928e6..cc7751f 100644 --- a/src/ChronosTime.php +++ b/src/ChronosTime.php @@ -172,6 +172,22 @@ public static function noon(): static return new static('12:00:00'); } + /** + * Returns instance set to end of day - either + * 23:59:59 or 23:59:59.999999 if `$microseconds` is true + * + * @param bool $microseconds Whether to set microseconds or not + * @return static + */ + public static function endOfDay(bool $microseconds = false): static + { + if ($microseconds) { + return new static('23:59:59.999999'); + } + + return new static('23:59:59'); + } + /** * Returns clock microseconds. * diff --git a/tests/TestCase/ChronosTimeTest.php b/tests/TestCase/ChronosTimeTest.php index 68f3e79..92b6786 100644 --- a/tests/TestCase/ChronosTimeTest.php +++ b/tests/TestCase/ChronosTimeTest.php @@ -128,6 +128,15 @@ public function testNoon(): void $this->assertSame('12:00:00.000000', $t->format('H:i:s.u')); } + public function testEndOfDay(): void + { + $t = ChronosTime::endOfDay(); + $this->assertSame('23:59:59.000000', $t->format('H:i:s.u')); + + $t = ChronosTime::endOfDay(microseconds: true); + $this->assertSame('23:59:59.999999', $t->format('H:i:s.u')); + } + public function testSetters(): void { $t = ChronosTime::midnight()->setHours(24);