Skip to content
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
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
32 changes: 19 additions & 13 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,21 +908,27 @@ 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
public function endOfDay(bool $microseconds = false): ChronosInterface
{
if (static::class === ChronosDate::class) {
trigger_error('2.5 endOfDay() will be removed in 3.x.', E_USER_DEPRECATED);
}

if ($microseconds) {
return $this->modify('23:59:59.999999');
}

return $this->modify('23:59:59');
}

/**
* 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 +942,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 +956,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 +970,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 +984,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 +996,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 +1008,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 +1022,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 +1041,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 +1056,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