Skip to content
Permalink
Browse files

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

  • Loading branch information...
Jelle Henkens
Jelle Henkens committed Jun 24, 2012
1 parent e2781a5 commit db7d5426ec58f24f909d5c66826a989a6f88fe08
Showing with 10 additions and 2 deletions.
  1. +7 −0 lib/Cake/Test/Case/Utility/CakeTimeTest.php
  2. +3 −2 lib/Cake/Utility/CakeTime.php
@@ -816,6 +816,13 @@ public function testFromString() {
$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();
}
/**
@@ -315,8 +315,9 @@ public static function fromString($dateString, $timezone = null) {
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);
}

0 comments on commit db7d542

Please sign in to comment.
You can’t perform that action at this time.