CakeTime no longer sets the timezone out of its scope on the date object

This commit is contained in:
Jelle Henkens 2012-06-24 11:10:28 +01:00
parent e2781a536a
commit db7d5426ec
2 changed files with 10 additions and 2 deletions

View file

@ -816,6 +816,13 @@ class CakeTimeTest extends CakeTestCase {
$result = $this->Time->fromString('+1 hour', $timezone);
$expected = $this->Time->convert(strtotime('+1 hour'), $timezone);
$this->assertEquals($expected, $result);
date_default_timezone_set('UTC');
$date = new DateTime('now', new DateTimeZone('Europe/London'));
$this->Time->fromString($date);
$this->assertEquals('Europe/London', $date->getTimeZone()->getName());
$this->_restoreSystemTimezone();
}
/**

View file

@ -315,8 +315,9 @@ class CakeTime {
if (is_integer($dateString) || is_numeric($dateString)) {
$date = intval($dateString);
} elseif (is_object($dateString) && $dateString instanceof DateTime) {
$dateString->setTimezone(new DateTimeZone(date_default_timezone_get()));
$date = (int)$dateString->format('U') + $dateString->getOffset();
$clone = clone $dateString;
$clone->setTimezone(new DateTimeZone(date_default_timezone_get()));
$date = (int)$clone->format('U') + $clone->getOffset();
} else {
$date = strtotime($dateString);
}