PostgresqlDateSql.php in Drupal 8
File
core/modules/views/src/Plugin/views/query/PostgresqlDateSql.php
View source
<?php
namespace Drupal\views\Plugin\views\query;
use Drupal\Core\Database\Connection;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
class PostgresqlDateSql implements DateSqlInterface {
use DependencySerializationTrait;
protected $database;
protected static $replace = [
'Y' => 'YYYY',
'y' => 'YY',
'M' => 'Mon',
'm' => 'MM',
'n' => 'MM',
'F' => 'Month',
'D' => 'Dy',
'd' => 'DD',
'l' => 'Day',
'j' => 'DD',
'W' => 'IW',
'H' => 'HH24',
'h' => 'HH12',
'i' => 'MI',
's' => 'SS',
'A' => 'AM',
];
public function __construct(Connection $database) {
$this->database = $database;
}
public function getDateField($field, $string_date) {
if ($string_date) {
return "TO_TIMESTAMP({$field}, 'YYYY-MM-DD\"T\"HH24:MI:SS')";
}
return "TO_TIMESTAMP({$field})";
}
public function getDateFormat($field, $format) {
$format = strtr($format, static::$replace);
return "TO_CHAR({$field}, '{$format}')";
}
public function setFieldTimezoneOffset(&$field, $offset) {
$field = "({$field} + INTERVAL '{$offset} SECONDS')";
}
public function setTimezoneOffset($offset) {
$this->database
->query("SET TIME ZONE INTERVAL '{$offset}' HOUR TO MINUTE");
}
}