spatie / period

Complex period comparisons
https://spatie.be/open-source
MIT License
1.56k stars 72 forks source link

Add ceilingEnd method with Precision mask #81

Closed morrislaptop closed 3 years ago

morrislaptop commented 3 years ago

From https://github.com/spatie/period/pull/78

This PR adds a method to the period class, ceilingEnd(?Precision $precision = null) which will get the included end DateTime to the last second of the precision passed to this method.

Useful when getting the end date of Period class in a DateTime object - for example if I passed Period::make('2018-01-01', '2018-01-15', Precision::DAY()), I would expect the endDate to be the end of 2018-01-15.. i.e. 23:59:59 that night.

It defaults to the current Precision of the period if not specified.

Usage:

$period = Period::make('2018-01-01', '2018-01-15', Precision::DAY());
$period->includedEnd(); // 2018-01-15 00:00:00
$period->ceilingEnd(); // 2018-01-15 23:59:59
$period = Period::make('2018-01-01', '2018-01-15', Precision::DAY());
$period->includedEnd(); // 2018-01-15 00:00:00
$period->ceilingEnd(Precision::MONTH()); // 2018-01-31 23:59:59
$period = Period::make('2018-01-01', '2018-01-15', Precision::DAY, Boundaries::EXCLUDE_END);
$period->includedEnd(); // 2018-01-14 00:00:00
$period->ceilingEnd(); // 2018-01-14 23:59:59
brendt commented 3 years ago

Awesome PR, can I just say how much I appreciate you immediately switching to the new v2 style? That rarely happens and is super awesome!

What are your thoughts about how the period class is now split? Feel free to share your feedback here: https://github.com/spatie/period/pull/80