diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 51c788e69..28ccb40aa 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -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(); } /** diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index f01154412..d2e3c6ffb 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -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); }