mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixed server offset calculation
This commit is contained in:
parent
9628910c86
commit
14b7210d2b
2 changed files with 12 additions and 1 deletions
|
@ -353,6 +353,13 @@ class CakeTimeTest extends CakeTestCase {
|
|||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -200,7 +200,11 @@ class CakeTime {
|
|||
* @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);
|
||||
|
|
Loading…
Reference in a new issue