From 14b7210d2b78612cb21ec692e527a322e811ad59 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 13 May 2012 06:20:29 +0530 Subject: [PATCH] Fixed server offset calculation --- lib/Cake/Test/Case/Utility/CakeTimeTest.php | 7 +++++++ lib/Cake/Utility/CakeTime.php | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 81e737c3fa5..d95455c3be2 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -353,6 +353,13 @@ public function testNiceShort() { $time = time() - DAY; $this->assertEquals('Yesterday, ' . date('H:i', $time), $this->Time->niceShort($time)); + + $oldTimezone = date_default_timezone_get(); + date_default_timezone_set('Europe/London'); + + $result = $this->Time->niceShort('2005-01-15 10:00:00', new DateTimeZone('Europe/Brussels')); + $this->assertEqual('Jan 15th 2005, 11:00', $result); + date_default_timezone_set($oldTimezone); } /** diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 70c6d46c3fd..475be34a9a4 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -200,7 +200,11 @@ protected static function _translateSpecifier($specifier) { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public static function convert($serverTime, $timezone) { - $serverOffset = self::serverOffset(); + static $serverTimezone = null; + if (is_null($serverTimezone) || (date_default_timezone_get() !== $serverTimezone->getName())) { + $serverTimezone = new DateTimeZone(date_default_timezone_get()); + } + $serverOffset = $serverTimezone->getOffset(new DateTime('@' . $serverTime)); $gmtTime = $serverTime - $serverOffset; if (is_numeric($timezone)) { $userOffset = $timezone * (60 * 60);