function DateSqlHandler::set_db_timezone in Date 8
Set the database timzone offset.
Setting the db timezone to UTC is done to ensure consistency in date handling whether or not the database can do proper timezone conversion.
Views filters that not exposed are cached and won't set the timezone so views date filters should add 'cacheable' => 'no' to their definitions to ensure that the database timezone gets set properly when the query is executed.
Parameters
string $offset: An offset value to set the database timezone to. This will only set a fixed offset, not a timezone, so any value other than '+00:00' should be used with caution.
1 call to DateSqlHandler::set_db_timezone()
- DateSqlHandler::__construct in date_api/
lib/ Drupal/ date_api/ DateSqlHandler.php - The object constuctor.
File
- date_api/
lib/ Drupal/ date_api/ DateSqlHandler.php, line 80
Class
- DateSqlHandler
- A class to manipulate date SQL.
Namespace
Drupal\date_apiCode
function set_db_timezone($offset = '+00:00') {
static $already_set = FALSE;
$type = db_driver();
if (!$already_set) {
switch ($type) {
case 'mysql':
case 'mysqli':
db_query("SET @@session.time_zone = '{$offset}'");
break;
case 'pgsql':
db_query("SET TIME ZONE INTERVAL '{$offset}' HOUR TO MINUTE");
break;
case 'sqlsrv':
// Issue #1201342, This is the wrong way to set the timezone, this
// still needs to be fixed. In the meantime, commenting this out makes
// SQLSRV functional.
// db_query('TimeZone.setDefault(TimeZone.getTimeZone("GMT"))');
break;
}
$already_set = TRUE;
}
}