Skip to content

Commit

Permalink
Add microseconds to Chronos::endOfDay()
Browse files Browse the repository at this point in the history
  • Loading branch information
othercorey committed Oct 15, 2023
1 parent 79b58b7 commit 406d717
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
28 changes: 15 additions & 13 deletions src/ChronosInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
26 changes: 14 additions & 12 deletions src/Traits/ModifierTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -908,8 +908,10 @@ 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
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down
6 changes: 5 additions & 1 deletion tests/TestCase/DateTime/StartEndOfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 406d717

Please sign in to comment.