Skip to content

Commit 848b7eb

Browse files
committed
use NoOverflow versions to get dates on the right side of month boundaries
1 parent 3d97d8e commit 848b7eb

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

app/Models/User.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public function usernameChangeCost()
329329
$tier = max(
330330
$this->usernameChangeHistory()
331331
->paid()
332-
->where('timestamp', '>', Carbon::now()->subYears(3))
332+
->where('timestamp', '>', Carbon::now()->subYearsNoOverflow(3))
333333
->count(),
334334
$minTier,
335335
);

tests/Models/UserTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function testUsernameChangeCostType(string $type, int $cost)
236236
public function testUsernameChangeCostWindow(int $years, int $cost)
237237
{
238238
$now = CarbonImmutable::now();
239-
$this->travelTo(CarbonImmutable::now()->subYears(3));
239+
$this->travelTo(CarbonImmutable::now()->subYearsNoOverflow(3));
240240

241241
$user = User::factory()->create();
242242
// every 6 months for 3 years = 6
@@ -251,7 +251,7 @@ public function testUsernameChangeCostWindow(int $years, int $cost)
251251
$this->travelTo(CarbonImmutable::now()->addMonthsNoOverflow(6));
252252
}
253253

254-
$this->travelTo($now->addYears($years));
254+
$this->travelTo($now->addYearsNoOverflow($years));
255255
$this->assertSame($cost, $user->usernameChangeCost());
256256
}
257257

0 commit comments

Comments
 (0)