Skip to content

Commit

Permalink
Reactored setCookie->setExpires 2038 bug on 32bit and its test
Browse files Browse the repository at this point in the history
  • Loading branch information
mbn18 committed Jan 4, 2014
1 parent 12f8f74 commit fab1278
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions library/Zend/Http/Header/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ public function setExpires($expires)
$tsExpires = $expires;
if (is_string($expires)) {
$tsExpires = strtotime($expires);
}

// if $tsExpires is invalid and PHP is compiled as 32bit. Check if the fail reason is the 2038 bug
if (!is_int($tsExpires) && is_string($expires) && PHP_INT_SIZE === 4) {
$dateTime = new \DateTime($expires);
if ( $dateTime->format('Y') > 2038) {
$tsExpires = PHP_INT_MAX;
// if $tsExpires is invalid and PHP is compiled as 32bit. Check if it fail reason is the 2038 bug
if (!is_int($tsExpires) && PHP_INT_SIZE === 4) {
$dateTime = new \DateTime($expires);
if ( $dateTime->format('Y') > 2038) {
$tsExpires = PHP_INT_MAX;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/ZendTest/Http/Header/SetCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ public function testSetCookieSetExpiresWithStringDateBiggerThen2038()
if ( PHP_INT_SIZE === 4 ) {
$setCookieHeader = new SetCookie('myname', 'myvalue', 'Thu, 01-Jan-2040 00:00:00 GMT');
$this->assertSame(2147483647, $setCookieHeader->getExpires(true));
} else {
$this->markTestSkipped('Testing set cookie expiry over 2038 is only relevant on 32bit systems');
}
}

Expand Down

0 comments on commit fab1278

Please sign in to comment.