Skip to content

Commit

Permalink
Merge pull request #83 from basz/timezone
Browse files Browse the repository at this point in the history
take timezone into account
  • Loading branch information
basz committed Feb 25, 2017
2 parents 37ccd7c + 5b7b565 commit a993ba3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Model/AbstractToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use DateTime;
use DateTimeInterface;
use DateTimeZone;

/**
* Provide basic functionality for both access tokens, refresh tokens and authorization codes
Expand Down Expand Up @@ -94,7 +95,7 @@ protected static function createNew(
$token->owner = $owner;
$token->client = $client;
$token->scopes = $scopes ?? [];
$token->expiresAt = $ttl ? (new DateTime())->modify("+$ttl seconds") : null;
$token->expiresAt = $ttl ? (new DateTime('now', new DateTimeZone('UTC')))->modify("+$ttl seconds") : null;

return $token;
}
Expand Down Expand Up @@ -158,15 +159,15 @@ public function getExpiresAt()
*/
public function getExpiresIn(): int
{
return $this->expiresAt->getTimestamp() - (new DateTime('now'))->getTimestamp();
return $this->expiresAt->getTimestamp() - (new DateTime('now', new DateTimeZone('UTC')))->getTimestamp();
}

/**
* Is the token expired?
*/
public function isExpired(): bool
{
return $this->expiresAt < new DateTime('now');
return $this->expiresAt < new DateTime('now', new DateTimeZone('UTC'));
}

/**
Expand Down

0 comments on commit a993ba3

Please sign in to comment.