Skip to content

Add isNowOrFuture() and isNowOrPast() methods #27

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

Merged

Conversation

AndrewMast
Copy link
Contributor

Why

Laravel recently introduced relative date shorthands to the Query Builder (laravel/framework#54408). Some of these methods include wherePast and whereFuture. Along with these methods, whereNowOrPast and whereNowOrFuture were introduced. These have been really helpful when querying timestamps.

However, after using these new query methods, I keep finding myself reaching for $carbon->isNowOrPast() and $carbon->isNowOrFuture(), but they don't exist in Carbon. I would have assumed something like this would have been implemented in Carbon already.

After a bit of digging, I found that isPast used to be inclusive in that it was an inverse of isFuture and would be true for the current time. This was fixed more than 10 years ago in briannesbitt/Carbon#142, and rightly so. However, I would like to bring back a bit of this functionality in two new methods.

What

Added the following methods:

  • isNowOrFuture: Copied isFuture but changed greaterThan to greaterThanOrEqualTo
  • isNowOrPast: Copied isPast but changed lessThan to lessThanOrEqualTo

Added tests in both tests/Carbon/IsTest.php and tests/CarbonImmutable/IsTest.php based on existing isFuture and isPast tests.

@AndrewMast
Copy link
Contributor Author

I see that I am getting a "merging is blocked" error. Should I have opened this on briannesbitt/Carbon?

Also on a side note, what is the recommended way to ensure our code matches the current style and passes the tests? Because the composer script for phpunit fails due to --verbose (apparently PHPUnit 10 removed the flag?), composer phpcs on a fresh clone finds a ton of formatting changes, and composer phpdoc adds #[ReturnTypeWillChange] to the createFromTimestamp method.

@kylekatarnls kylekatarnls added the enhancement New feature or request label Mar 27, 2025
@kylekatarnls kylekatarnls added this to the 3.8.7 milestone Mar 27, 2025
@kylekatarnls
Copy link
Contributor

I see that I am getting a "merging is blocked" error. Should I have opened this on briannesbitt/Carbon?

Nope, it's the same on the other repo, merging is blocked as long as test didn't complete and pass, and a first approval is needed to run the tests on GitHub Actions.

@kylekatarnls kylekatarnls merged commit 6d16a8a into CarbonPHP:master Mar 27, 2025
25 checks passed
@AndrewMast AndrewMast deleted the feat/is-now-or-past-future branch March 27, 2025 15:26
@AndrewMast AndrewMast mentioned this pull request Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants