Skip to content

Commit

Permalink
Merge pull request #261 from PHP-Open-Source-Saver/bugfix/260-carbon-…
Browse files Browse the repository at this point in the history
…diffin-methods

Cater for both Carbon v2 and v3 - issue #260
  • Loading branch information
Messhias authored Jul 24, 2024
2 parents 7e91edf + e6aab32 commit b163d51
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
laravel: 11.*
stability: prefer-stable
coverage: xdebug
- php: 8.3
laravel: 11.*
carbon: 3.*

name: 'P${{ matrix.php }} L${{ matrix.laravel }} ${{ matrix.stability }} c:${{ matrix.coverage }}'

Expand Down Expand Up @@ -55,6 +58,11 @@ jobs:
run: |
composer require "illuminate/contracts:${{ matrix.laravel }}" --no-interaction --no-progress --no-update
- name: Set carbon version
if: ${{ matrix.carbon }}
run: |
composer require "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-progress --no-update
- name: Cache dependencies
uses: actions/cache@v4
with:
Expand Down
9 changes: 8 additions & 1 deletion src/Blacklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ protected function getMinutesUntilExpired(Payload $payload)
// get the latter of the two expiration dates and find
// the number of minutes until the expiration date,
// plus 1 minute to avoid overlap
return round($exp->max($iat->addMinutes($this->refreshTTL))->addMinute()->diffInRealMinutes(null, true));
$intermediateResult = $exp->max($iat->addMinutes($this->refreshTTL))->addMinute();

// Handle Carbon 2 vs 3 deprecation of "Real" diff functions, see https://github.com/PHP-Open-Source-Saver/jwt-auth/issues/260
if (method_exists($intermediateResult, 'diffInRealMinutes')) {
return round($intermediateResult->diffInRealMinutes(null, true));
} else {
return (int) round($intermediateResult->diffInMinutes(null, true));
}
}

/**
Expand Down

0 comments on commit b163d51

Please sign in to comment.