Skip to content

Commit 4ddb7e6

Browse files
authored
refactor: use diff for remaining throttle seconds (#537)
1 parent d44165f commit 4ddb7e6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/UserInterface/Components/ThrottledComponent.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace ARKEcosystem\Foundation\UserInterface\Components;
66

77
use ARKEcosystem\Foundation\UserInterface\Components\Concerns\HandleToast;
8+
use Carbon\Carbon;
89
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
910
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
1011
use Illuminate\Support\Facades\RateLimiter;
@@ -31,10 +32,11 @@ final protected function getThrottlingAvailableIn(): string
3132

3233
$secondsUntilAvailable = RateLimiter::availableIn($this->getRateLimitKey($throttlingKey));
3334

34-
$parts = explode(':', gmdate('H:i', $secondsUntilAvailable));
35+
$diff = Carbon::createFromTimeStamp($secondsUntilAvailable)->diff(Carbon::createFromTimeStamp(0));
3536

36-
$hours = (int) $parts[0];
37-
$minutes = (int) $parts[1];
37+
$hours = $diff->h + ($diff->d * 24);
38+
$minutes = $diff->i;
39+
$seconds = $diff->s;
3840

3941
if ($hours > 0) {
4042
if ($minutes > 0) {

0 commit comments

Comments
 (0)