Skip to content

Commit

Permalink
Add ChronosTime::endOfDay()
Browse files Browse the repository at this point in the history
  • Loading branch information
othercorey committed Oct 14, 2023
1 parent 54164f6 commit 0436341
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ChronosTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/TestCase/ChronosTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0436341

Please sign in to comment.