diff --git a/src/ChronosTime.php b/src/ChronosTime.php index 7c928e6..e7a70fc 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 with optional + * microseconds. + * + * @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..7c743df 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(microseconds: false); + $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);