[Bug]: Comparison fails in recordStreak
PerryRylance opened this issue · comments
What happened?
I was testing streak continuation this morning and have found that the check at HasStreaks:51
for strict equality $diffInDays === 1
.
If you see the screenshot attached you'll see that even though $diffInDays
shows as 1, this evaluates to false. This is because $diffInDays
is a float.
How to reproduce the bug
Try with Laravel 11 / Carbon 3.
Package Version
1.2
PHP Version
8.2
Laravel Version
11.0
Which operating systems does with happen with?
Windows
Notes
After a quick search I found this article, breaking change in Carbon 3.0 is that these will be returned as floats now.
I cloned this repo and ran the test suite on a fresh install and can confirm that your tests are also failing on this.
Thank you for this library!
I fixed this locally by adding intval
at HasStreaks:51
, I tried to branch and submit a PR but looks like the repo isn't open.
@PerryRylance What do you mean the repo isn't open? You should be able to open a PR in this repo
@cjmellor Tried again just now, maybe there's something wrong with my client or account.
remote: Permission to cjmellor/level-up.git denied to PerryRylance.
fatal: unable to access 'https://github.com/cjmellor/level-up/': The requested URL returned error: 403
Yeah, weird!
If you send me the code and instructions I can look at adding it.
Please open HasStreaks
and go to recordStreak
. Right at the top where $diffInDays
is calculated, you need to wrap the expression in intval
:
$diffInDays = intval($this->getStreakLastActivity($activity)
->activity_at
->startOfDay()
->diffInDays(now()->startOfDay()));
If you do a fresh install and composer install
, then run the tests before making this change - you'll see your test suite fails. If you then make this change, then run the tests again, you'll see it will pass 💃
Cheers @PerryRylance