public function Sql::setupTimezone in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::setupTimezone()
Set the database to the current user timezone,
Return value
string The current timezone as returned by drupal_get_user_timezone().
Overrides QueryPluginBase::setupTimezone
1 call to Sql::setupTimezone()
- Sql::getDateField in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Returns a Unix timestamp to database native timestamp expression.
File
- core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php, line 1727 - Contains \Drupal\views\Plugin\views\query\Sql.
Class
- Sql
- Views query plugin for an SQL query.
Namespace
Drupal\views\Plugin\views\queryCode
public function setupTimezone() {
$timezone = drupal_get_user_timezone();
// set up the database timezone
$db_type = Database::getConnection()
->databaseType();
if (in_array($db_type, array(
'mysql',
'pgsql',
))) {
$offset = '+00:00';
static $already_set = FALSE;
if (!$already_set) {
if ($db_type == 'pgsql') {
Database::getConnection()
->query("SET TIME ZONE INTERVAL '{$offset}' HOUR TO MINUTE");
}
elseif ($db_type == 'mysql') {
Database::getConnection()
->query("SET @@session.time_zone = '{$offset}'");
}
$already_set = TRUE;
}
}
return $timezone;
}