From 5bcd8bf629634070022005ce702725074c2b31d0 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Tue, 18 Sep 2012 23:05:44 -0400
Subject: [PATCH] Auto detect DB's timezone offset

---
 include/class.config.php | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/include/class.config.php b/include/class.config.php
index f7eafc4a4..96674dd3a 100644
--- a/include/class.config.php
+++ b/include/class.config.php
@@ -36,7 +36,8 @@ class Config {
         if(!$id && !($id=$this->getId()))
             return false;
 
-        $sql='SELECT * FROM '.CONFIG_TABLE
+        $sql='SELECT *, (TIME_TO_SEC(TIMEDIFF(NOW(), UTC_TIMESTAMP()))/3600) as db_tz_offset '
+            .' FROM '.CONFIG_TABLE
             .' WHERE id='.db_input($id);
         
         if(!($res=db_query($sql)) || !db_num_rows($res))
@@ -45,15 +46,6 @@ class Config {
             
         $this->config = db_fetch_array($res);
         $this->id = $this->config['id'];
-        //Figure out DB timezone 
-        if(($dbtz=db_timezone())) {
-            if($dbtz=='SYSTEM')
-                $this->config['dbtz_offset'] = preg_replace('/([+-]\d{2})(\d{2})/', '\1', date('O'));
-            else
-                $this->config['dbtz_offset'] = preg_replace('/([+-]\d{2})(:)(\d{2})/', '\1', $dbtz);
-        } else {
-            $this->config['dbtz_offset'] = 0;
-        }
 
         //Get the default time zone
         // We can't JOIN timezone table above due to upgrade support.
@@ -110,7 +102,7 @@ class Config {
     }
     
     function getDBTZoffset() {
-        return $this->config['dbtz_offset'];
+        return $this->config['db_tz_offset'];
     }
 
     /* Date & Time Formats */
-- 
GitLab