class PostgresqlDateSql in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/query/PostgresqlDateSql.php \Drupal\views\Plugin\views\query\PostgresqlDateSql
PostgreSQL-specific date handling.
@internal This class should only be used by the Views SQL query plugin.
Hierarchy
- class \Drupal\views\Plugin\views\query\PostgresqlDateSql implements DateSqlInterface uses DependencySerializationTrait
Expanded class hierarchy of PostgresqlDateSql
See also
\Drupal\views\Plugin\views\query\Sql
1 file declares its use of PostgresqlDateSql
- PostgresqlDateSqlTest.php in core/
modules/ views/ tests/ src/ Unit/ Plugin/ views/ query/ PostgresqlDateSqlTest.php
1 string reference to 'PostgresqlDateSql'
- views.services.yml in core/
modules/ views/ views.services.yml - core/modules/views/views.services.yml
1 service uses PostgresqlDateSql
- pgsql.views.date_sql in core/
modules/ views/ views.services.yml - Drupal\views\Plugin\views\query\PostgresqlDateSql
File
- core/
modules/ views/ src/ Plugin/ views/ query/ PostgresqlDateSql.php, line 16
Namespace
Drupal\views\Plugin\views\queryView source
class PostgresqlDateSql implements DateSqlInterface {
use DependencySerializationTrait;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* An array of PHP-to-PostgreSQL replacement patterns.
*
* @var array
*/
protected static $replace = [
'Y' => 'YYYY',
'y' => 'YY',
'M' => 'Mon',
'm' => 'MM',
// No format for Numeric representation of a month, without leading zeros.
'n' => 'MM',
'F' => 'Month',
'D' => 'Dy',
'd' => 'DD',
'l' => 'Day',
// No format for Day of the month without leading zeros.
'j' => 'DD',
'W' => 'IW',
'H' => 'HH24',
'h' => 'HH12',
'i' => 'MI',
's' => 'SS',
'A' => 'AM',
];
/**
* Constructs the PostgreSQL-specific date sql class.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public function getDateField($field, $string_date) {
if ($string_date) {
// Ensures compatibility with field offset operation below.
return "TO_TIMESTAMP({$field}, 'YYYY-MM-DD\"T\"HH24:MI:SS')";
}
return "TO_TIMESTAMP({$field})";
}
/**
* {@inheritdoc}
*/
public function getDateFormat($field, $format) {
$format = strtr($format, static::$replace);
return "TO_CHAR({$field}, '{$format}')";
}
/**
* {@inheritdoc}
*/
public function setFieldTimezoneOffset(&$field, $offset) {
$field = "({$field} + INTERVAL '{$offset} SECONDS')";
}
/**
* {@inheritdoc}
*/
public function setTimezoneOffset($offset) {
$this->database
->query("SET TIME ZONE INTERVAL '{$offset}' HOUR TO MINUTE");
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
PostgresqlDateSql:: |
protected | property | The database connection. | |
PostgresqlDateSql:: |
protected static | property | An array of PHP-to-PostgreSQL replacement patterns. | |
PostgresqlDateSql:: |
public | function |
Returns a native database expression for a given field. Overrides DateSqlInterface:: |
|
PostgresqlDateSql:: |
public | function |
Creates a native database date formatting. Overrides DateSqlInterface:: |
|
PostgresqlDateSql:: |
public | function |
Applies the given offset to the given field. Overrides DateSqlInterface:: |
|
PostgresqlDateSql:: |
public | function |
Set the database to the given timezone. Overrides DateSqlInterface:: |
|
PostgresqlDateSql:: |
public | function | Constructs the PostgreSQL-specific date sql class. |