CRM-9683 add functions to set timezone in mysql based on UF, note that this is not...
[civicrm-core.git] / CRM / Utils / System / Drupal.php
index 3ff008b6b7ca9c81100b0b53c61baddac56f0ff6..fda57c0385727286cb67e173ed0b285bf2121983 100644 (file)
@@ -1065,6 +1065,32 @@ AND    u.status = 1
     }
   }
 
+  /**
+   * Get timezone from Drupal
+   * @return boolean|string
+   */
+  function getTimeZoneOffset(){
+    global $user;
+    if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
+      $timezone = $user->timezone;
+    } else {
+      $timezone = variable_get('date_default_timezone', null);
+    }
+    $tzObj = new DateTimeZone($timezone);
+    $dateTime = new DateTime("now", $tzObj);
+    $tz = $tzObj->getOffset($dateTime);
+
+    if(empty($tz)){
+      return false;
+    }
+
+    $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, ($tz/60)%60 );
+
+    if($timeZoneOffset > 0){
+      $timeZoneOffset = '+' . $timeZoneOffset;
+    }
+    return $timeZoneOffset;
+  }
   /**
    * Reset any system caches that may be required for proper CiviCRM
    * integration.