Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ChronosTime::endOfDay() #439

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 - 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.
*
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();
$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