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 ceilingEnd method with Precision mask #81

Merged
merged 4 commits into from
Feb 26, 2021

Conversation

morrislaptop
Copy link
Contributor

From #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
Copy link
Collaborator

brendt commented Feb 26, 2021

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: #80

@brendt brendt merged commit 3597959 into spatie:2.0 Feb 26, 2021
@morrislaptop morrislaptop deleted the ceiling-end-2 branch February 26, 2021 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants