DateTime::getTimestamp() is PHP5.3+

This commit is contained in:
mark_story 2013-04-11 13:39:05 -04:00
parent 5e00fdfce5
commit 8bd1980dd4
2 changed files with 4 additions and 4 deletions

View file

@ -846,7 +846,7 @@ class CakeTimeTest extends CakeTestCase {
$date = new DateTime('+1 hour', new DateTimeZone('America/New_York')); $date = new DateTime('+1 hour', new DateTimeZone('America/New_York'));
$result = $this->Time->fromString($date, 'UTC'); $result = $this->Time->fromString($date, 'UTC');
$date->setTimezone(new DateTimeZone('UTC')); $date->setTimezone(new DateTimeZone('UTC'));
$expected = $date->getTimestamp() + $date->getOffset(); $expected = $date->format('U') + $date->getOffset();
$this->assertWithinMargin($expected, $result, 1); $this->assertWithinMargin($expected, $result, 1);
@ -871,7 +871,7 @@ class CakeTimeTest extends CakeTestCase {
Configure::write('Config.timezone', date_default_timezone_get()); Configure::write('Config.timezone', date_default_timezone_get());
$date = new DateTime('2013-04-09'); $date = new DateTime('2013-04-09');
$result = $this->Time->fromString($date); $result = $this->Time->fromString($date);
$this->assertEquals($result, $date->getTimestamp()); $this->assertEquals($result, $date->format('U'));
} }
/** /**

View file

@ -325,9 +325,9 @@ class CakeTime {
) { ) {
$clone = clone $dateString; $clone = clone $dateString;
$clone->setTimezone(new DateTimeZone(date_default_timezone_get())); $clone->setTimezone(new DateTimeZone(date_default_timezone_get()));
$date = (int)$clone->getTimestamp() + $clone->getOffset(); $date = (int)$clone->format('U') + $clone->getOffset();
} elseif ($dateString instanceof DateTime) { } elseif ($dateString instanceof DateTime) {
$date = (int)$dateString->getTimeStamp(); $date = (int)$dateString->format('U');
} else { } else {
$date = strtotime($dateString); $date = strtotime($dateString);
} }