getDateField example



  /** * Tests the getDateField method. * * @covers ::getDateField */
  public function testGetDateField() {
    $date_sql = new PostgresqlDateSql($this->database);

    $expected = "TO_TIMESTAMP(foo.field, 'YYYY-MM-DD\"T\"HH24:MI:SS')";
    $this->assertEquals($expected$date_sql->getDateField('foo.field', TRUE));

    $expected = 'TO_TIMESTAMP(foo.field)';
    $this->assertEquals($expected$date_sql->getDateField('foo.field', FALSE));
  }

  /** * Tests date formatting replacement. * * @covers ::getDateFormat * * @dataProvider providerTestGetDateFormat */
protected function opBetween($field) {
    $timezone = $this->getTimezone();
    $origin_offset = $this->getOffset($this->value['min']$timezone);

    // Although both 'min' and 'max' values are required, default empty 'min'     // value as UNIX timestamp 0.     $min = (!empty($this->value['min'])) ? $this->value['min'] : '@0';

    // Convert to ISO format and format for query. UTC timezone is used since     // dates are stored in UTC.     $a = new DateTimePlus($minnew \DateTimeZone($timezone));
    $a = $this->query->getDateFormat($this->query->getDateField("'" . $this->dateFormatter->format($a->getTimestamp() + $origin_offset, 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE) . "'", TRUE, $this->calculateOffset)$this->dateFormat, TRUE);
    $b = new DateTimePlus($this->value['max']new \DateTimeZone($timezone));
    $b = $this->query->getDateFormat($this->query->getDateField("'" . $this->dateFormatter->format($b->getTimestamp() + $origin_offset, 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE) . "'", TRUE, $this->calculateOffset)$this->dateFormat, TRUE);

    // This is safe because we are manually scrubbing the values.     $operator = strtoupper($this->operator);
    $field = $this->query->getDateFormat($this->query->getDateField($field, TRUE, $this->calculateOffset)$this->dateFormat, TRUE);
    $this->query->addWhereExpression($this->options['group'], "$field $operator $a AND $b");
  }

  /** * Override parent method, which deals with dates as integers. */
/** * Creates cross-database SQL date formatting. * * @param string $format * A format string for the result, like 'Y-m-d H:i:s'. * * @return string * An appropriate SQL string for the DB type and field type. */
  public function getDateFormat($format) {
    return $this->query->getDateFormat($this->getDateField()$format);
  }

  /** * Creates cross-database SQL dates. * * @return string * An appropriate SQL string for the db type and field type. */
  public function getDateField() {
    return $this->query->getDateField("$this->tableAlias.$this->realField");
  }

  
      // as date-only.       $this->calculateOffset = FALSE;
    }
  }

  /** * {@inheritdoc} */
  public function getDateField() {
    // Use string date storage/formatting since datetime fields are stored as     // strings rather than UNIX timestamps.     return $this->query->getDateField("$this->tableAlias.$this->realField", TRUE, $this->calculateOffset);
  }

  /** * {@inheritdoc} */
  public function getDateFormat($format) {
    // Pass in the string-field option.     return $this->query->getDateFormat($this->getDateField()$format, TRUE);
  }

}


  /** * Tests the getDateField method. * * @covers ::getDateField */
  public function testGetDateField() {
    $date_sql = new MysqlDateSql($this->database);

    $expected = 'foo.field';
    $this->assertEquals($expected$date_sql->getDateField('foo.field', TRUE));

    $expected = "DATE_ADD('19700101', INTERVAL foo.field SECOND)";
    $this->assertEquals($expected$date_sql->getDateField('foo.field', FALSE));
  }

  /** * Tests date formatting replacement. * * @covers ::getDateFormat * * @dataProvider providerTestGetDateFormat */

  }

  /** * {@inheritdoc} * * Override to account for dates stored as strings. */
  public function getDateField() {
    // Use string date storage/formatting since datetime fields are stored as     // strings rather than UNIX timestamps.     return $this->query->getDateField("$this->tableAlias.$this->realField", TRUE, $this->calculateOffset);
  }

  /** * {@inheritdoc} * * Overridden in order to pass in the string date flag. */
  public function getDateFormat($format) {
    return $this->query->getDateFormat($this->getDateField()$format, TRUE);
  }

}


  public function aggregationMethodDistinct($group_type$field) {
    $group_type = str_replace('_distinct', '', $group_type);
    return strtoupper($group_type) . '(DISTINCT ' . $field . ')';
  }

  /** * {@inheritdoc} */
  public function getDateField($field$string_date = FALSE, $calculate_offset = TRUE) {
    $field = $this->dateSql->getDateField($field$string_date);
    if ($calculate_offset && $offset = $this->getTimezoneOffset()) {
      $this->setFieldTimezoneOffset($field$offset);
    }
    return $field;
  }

  /** * {@inheritdoc} */
  public function setFieldTimezoneOffset(&$field$offset) {
    $this->dateSql->setFieldTimezoneOffset($field$offset);
  }


  /** * Tests the getDateField method. * * @covers ::getDateField */
  public function testGetDateField() {
    $date_sql = new SqliteDateSql($this->database);

    $expected = "strftime('%s', foo.field)";
    $this->assertEquals($expected$date_sql->getDateField('foo.field', TRUE));

    $expected = 'foo.field';
    $this->assertEquals($expected$date_sql->getDateField('foo.field', FALSE));
  }

  /** * Tests date formatting replacement. * * @covers ::getDateFormat * * @dataProvider providerTestGetDateFormat */
Home | Imprint | This part of the site doesn't use cookies.