function date_sql_handler::set_db_timezone in Date 6.2
Same name and namespace in other branches
- 5.2 date_api_sql.inc \date_sql_handler::set_db_timezone()
- 6 date_api_sql.inc \date_sql_handler::set_db_timezone()
- 7.3 date_api/date_api_sql.inc \date_sql_handler::set_db_timezone()
- 7 date_api/date_api_sql.inc \date_sql_handler::set_db_timezone()
- 7.2 date_api/date_api_sql.inc \date_sql_handler::set_db_timezone()
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
$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.
File
- ./
date_api_sql.inc, line 125 - SQL date functions.
Class
- date_sql_handler
- A class to manipulate date SQL.
Code
function set_db_timezone($offset = '+00:00') {
static $already_set = FALSE;
$type = $GLOBALS['db_type'];
if (!$already_set) {
if (($type == 'mysqli' || $type == 'mysql') && version_compare(db_version(), '4.1.3', '>=')) {
db_query("SET @@session.time_zone = '{$offset}'");
}
elseif ($type == 'pgsql') {
db_query("SET TIME ZONE INTERVAL '{$offset}' HOUR TO MINUTE");
}
$already_set = TRUE;
}
}