From 87a81d718161910ebaedc5de17fcc60665106e28 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Thu, 21 May 2015 17:35:23 -0500 Subject: [PATCH] i18n: Properly convert date time zones without the intl extension --- include/class.format.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/class.format.php b/include/class.format.php index d418bf762..b3ff5bf5c 100644 --- a/include/class.format.php +++ b/include/class.format.php @@ -465,11 +465,15 @@ class Format { return $formatter->format($timestamp); } // Fallback using strftime + static $user_timezone; + if (!isset($user_timezone)) + $user_timezone = new DateTimeZone($cfg->getTimezone() ?: date_default_timezone_get()); + $format = self::getStrftimeFormat($format); - // TODO: Properly convert to local time + // Properly convert to user local time $time = DateTime::createFromFormat('U', $timestamp, new DateTimeZone('UTC')); - $time->setTimeZone(new DateTimeZone($cfg->getTimezone() ?: date_default_timezone_get())); - $timestamp = $time->getTimestamp(); + $offset = $user_timezone->getOffset($time); + $timestamp = $time->getTimestamp() + $offset; return strftime($format ?: $strftimeFallback, $timestamp); } -- GitLab