[11.x] Fix query builder whereBetween
with CarbonPeriod and Carbon 3
#50792
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.
This PR fixes the query builder's
whereBetween()
andhavingBetween()
methods by callinggetStartDate()
andgetEndDate()
onCarbonPeriod
, instead of using its$start
and$end
properties. Currently, using Carbon 3,$period->start
is always2000-01-01
and$period->end
is alwaysnull
(see briannesbitt/Carbon#2982).In Carbon 2 this is actually exactly what
$start
and$end
already do—they are not defined, so they go through theCarbonPeriod
class's__get()
method, which callsgetStartDate()
andgetEndDate()
(https://github.com/briannesbitt/Carbon/blob/2.x/src/Carbon/CarbonPeriod.php#L757).In Carbon 3 those getters are all still set up exactly the same way, but they don't work (I assume this was unintentional).
CarbonPeriod
now extends PHP'sDatePeriod
class, which actually defines$start
and$end
properties, so the getters are never called.