Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SqliteDateSql.php

function SqliteDateSql::getDateFormat

Overrides DateSqlInterface::getDateFormat

File

core/modules/views/src/Plugin/views/query/SqliteDateSql.php, line 85

Class

SqliteDateSql
SQLite-specific date handling.

Namespace

Drupal\views\Plugin\views\query

Code

public function getDateFormat($field, $format) {
    $format = strtr($format, static::$replace);
    // SQLite does not have an ISO week substitution string, so it needs special
    // handling.
    // @see http://wikipedia.org/wiki/ISO_week_date#Calculation
    // @see http://stackoverflow.com/a/15511864/1499564
    if ($format === '%W') {
        $expression = "((strftime('%j', date(strftime('%Y-%m-%d', {$field}, 'unixepoch'), '-3 days', 'weekday 4')) - 1) / 7 + 1)";
    }
    else {
        $expression = "strftime('{$format}', {$field}, 'unixepoch')";
    }
    // The expression yields a string, but the comparison value is an integer in
    // case the comparison value is a float, integer, or numeric. All of the
    // above SQLite format tokens only produce integers. However, the given
    // $format may contain 'Y-m-d', which results in a string.
    // @see \Drupal\sqlite\Driver\Database\sqlite\Connection::expandArguments()
    // @see http://www.sqlite.org/lang_datefunc.html
    // @see http://www.sqlite.org/lang_expr.html#castexpr
    if (preg_match('/^(?:%\\w)+$/', $format)) {
        $expression = "CAST({$expression} AS NUMERIC)";
    }
    return $expression;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal