Add isNowOrFuture()
and isNowOrPast()
methods
#27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
Laravel recently introduced relative date shorthands to the Query Builder (laravel/framework#54408). Some of these methods include
wherePast
andwhereFuture
. Along with these methods,whereNowOrPast
andwhereNowOrFuture
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 ofisFuture
and would betrue
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
: CopiedisFuture
but changedgreaterThan
togreaterThanOrEqualTo
isNowOrPast
: CopiedisPast
but changedlessThan
tolessThanOrEqualTo
Added tests in both
tests/Carbon/IsTest.php
andtests/CarbonImmutable/IsTest.php
based on existingisFuture
andisPast
tests.