Open daniser opened 6 months ago
Before the 3.0, the Carbon::diff
method simply returned a \DateInterval
but now there is an intermediate CarbonInterval
object that is created with an interval_spec string.
As stated in the DateInterval
phpdoc
If the DateInterval object was created by DateTimeImmutable::diff() or DateTime::diff(), then this is the total number of full days between the start and end dates. Otherwise, days will be false.
It's a problem for the days
property, it's never set and unfortunately it can't be set manually. I tried a lot of things but I don't think there is an easy solution to handle this directly in the vendor
@daniser You can replace all the Carbon::diff
in your code with the Carbon::diffAsDateInterval
method to keep the same behaviour, or you can use the Carbon::diffInDays
method but you'll get a float so don't forget to cast it if you need an integer
You can also use ->format('%a')
instead of ->days
it's got overridden recently to behave the same way it would with a diff DateInterval
Hello,
I encountered an issue with the following code:
3
false
Carbon version: 3.3.1
PHP version: 8.3.4
I expected to get:
But I actually get:
Thanks!