public static function setTimeZone($time_zone = NULL) { global $config_vars; $time_zone = Misc::trimSortPrefix(trim($time_zone)); //Default to system local timezone if no timezone is specified. if ($time_zone == '') { if (isset($config_vars['other']['system_timezone'])) { $time_zone = $config_vars['other']['system_timezone']; } else { //$time_zone = 'GMT'; $time_zone = date('e'); } } if ($time_zone == self::$time_zone) { Debug::text('TimeZone already set to: ' . $time_zone, __FILE__, __LINE__, __METHOD__, 10); return TRUE; } if ($time_zone != '') { Debug::text('Setting TimeZone: ' . $time_zone, __FILE__, __LINE__, __METHOD__, 10); self::$time_zone = $time_zone; @date_default_timezone_set($time_zone); putenv('TZ=' . $time_zone); global $db; if (isset($db) and is_object($db) and strncmp($db->databaseType, 'mysql', 5) == 0) { if (@$db->Execute('SET SESSION time_zone=\'' . $time_zone . '\'') == FALSE) { return FALSE; } } return TRUE; } else { //PHP doesn't have a unsetenv(), so this will cause the system to default to UTC. //If we don't do this then looping over users and setting timezones, if a user //doesn't have a timezone set, it will cause them to use the previous users timezone. //This way they at least use UTC and hopefully the issue will stand out more. //date_default_timezone_set( '' ); putenv('TZ='); } return FALSE; }
public static function setTimeZone($time_zone = NULL) { global $config_vars, $current_user_prefs; $time_zone = Misc::trimSortPrefix(trim($time_zone)); //Default to system local timezone if no timezone is specified. if ($time_zone == '' or strtolower($time_zone) == 'system/localtime') { //System/Localtime is an invalid timezone, so default to GMT instead. if (isset($current_user_prefs) and is_object($current_user_prefs)) { //When TTDate is called from the API directly, its not called statically, so //this forces __construct() to call setTimeZone and for the timezone to be set back to the system defined timezone after //$current_user->getUserPreferenceObject()->setDateTimePreferences(); is called. //This checks to see if a user is logged in and uses their own preferences instead. $time_zone = $current_user_prefs->getTimeZone(); } elseif (isset($config_vars['other']['system_timezone'])) { $time_zone = $config_vars['other']['system_timezone']; } else { //$time_zone = date('e'); //Newer versions of PHP return System/Localtime which is invalid, so force to GMT instead $time_zone = 'GMT'; } } if ($time_zone == self::$time_zone) { Debug::text('TimeZone already set to: ' . $time_zone, __FILE__, __LINE__, __METHOD__, 10); return TRUE; } if ($time_zone != '') { Debug::text('Setting TimeZone: ' . $time_zone, __FILE__, __LINE__, __METHOD__, 10); global $db; if (isset($db) and is_object($db) and strncmp($db->databaseType, 'mysql', 5) == 0) { if (@$db->Execute('SET SESSION time_zone=' . $db->qstr($time_zone)) == FALSE) { return FALSE; } } //Set timezone AFTER MySQL query above, so if it fails we don't set the timezone below at all. self::$time_zone = $time_zone; @date_default_timezone_set($time_zone); putenv('TZ=' . $time_zone); return TRUE; } else { //PHP doesn't have a unsetenv(), so this will cause the system to default to UTC. //If we don't do this then looping over users and setting timezones, if a user //doesn't have a timezone set, it will cause them to use the previous users timezone. //This way they at least use UTC and hopefully the issue will stand out more. //date_default_timezone_set( '' ); putenv('TZ='); } return FALSE; }