Skip to content

Commit b4f63cf

Browse files
authored
Merge pull request #2343 from geoffrey-brier/fix-is-account-non-expired
Fix isAccountNonExpired after year 2038
2 parents 036be38 + 9622f52 commit b4f63cf

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

Model/User.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Collections\Collection;
1515
use Doctrine\Common\Collections\ArrayCollection;
16+
use FOS\UserBundle\Util\DateUtil;
1617

1718
/**
1819
* Storage agnostic user object
@@ -317,7 +318,7 @@ public function isAccountNonExpired()
317318
return false;
318319
}
319320

320-
if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
321+
if (null !== $this->expiresAt && DateUtil::getSeconds($this->expiresAt->diff(new \DateTime())) <= 0) {
321322
return false;
322323
}
323324

Tests/Util/DateUtilTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\UserBundle\Tests\Util;
13+
14+
use FOS\UserBundle\Util\DateUtil;
15+
16+
class DateUtilTest extends \PHPUnit_Framework_TestCase
17+
{
18+
public function testGetSeconds()
19+
{
20+
$this->assertEquals(86400, DateUtil::getSeconds(new \DateInterval('P1D')));
21+
}
22+
}

Util/DateUtil.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\UserBundle\Util;
13+
14+
class DateUtil
15+
{
16+
/**
17+
* @param \DateInterval $interval
18+
*
19+
* @return int
20+
*/
21+
public static function getSeconds(\DateInterval $interval)
22+
{
23+
$datetime = new \DateTime('@0');
24+
25+
return $datetime->add($interval)->getTimestamp();
26+
}
27+
}

0 commit comments

Comments
 (0)