You are here

class Date in Drupal 10

Same name in this branch
  1. 10 core/lib/Drupal/Core/Render/Element/Date.php \Drupal\Core\Render\Element\Date
  2. 10 core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date
  3. 10 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date
  4. 10 core/modules/views/src/Plugin/views/argument/Date.php \Drupal\views\Plugin\views\argument\Date
  5. 10 core/modules/views/src/Plugin/views/field/Date.php \Drupal\views\Plugin\views\field\Date
  6. 10 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date
  7. 10 core/modules/datetime/src/Plugin/views/sort/Date.php \Drupal\datetime\Plugin\views\sort\Date
  8. 10 core/modules/datetime/src/Plugin/views/argument/Date.php \Drupal\datetime\Plugin\views\argument\Date
Same name and namespace in other branches
  1. 8 core/modules/datetime/src/Plugin/views/sort/Date.php \Drupal\datetime\Plugin\views\sort\Date
  2. 9 core/modules/datetime/src/Plugin/views/sort/Date.php \Drupal\datetime\Plugin\views\sort\Date

Basic sort handler for datetime fields.

This handler enables granularity, which is the ability to make dates equivalent based upon nearness.

Plugin annotation

@ViewsSort("datetime");

Hierarchy

Expanded class hierarchy of Date

23 string references to 'Date'
Date::getSortName in core/modules/views/src/Plugin/views/argument/Date.php
Datetime::processDatetime in core/lib/Drupal/Core/Datetime/Element/Datetime.php
Expands a datetime element type into date and/or time elements.
DateTimeSchemaTest::testDateTimeSchema in core/modules/datetime/tests/src/Kernel/Views/DateTimeSchemaTest.php
Tests argument plugin schema.
DbLogController::eventDetails in core/modules/dblog/src/Controller/DbLogController.php
Displays details about a specific database log message.
DbLogController::overview in core/modules/dblog/src/Controller/DbLogController.php
Displays a listing of database log messages.

... See full list

File

core/modules/datetime/src/Plugin/views/sort/Date.php, line 17

Namespace

Drupal\datetime\Plugin\views\sort
View source
class Date extends NumericDate {
  use FieldAPIHandlerTrait;

  /**
   * Determines if the timezone offset is calculated.
   *
   * @var bool
   */
  protected $calculateOffset = TRUE;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $definition = $this
      ->getFieldStorageDefinition();
    if ($definition
      ->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {

      // Timezone offset calculation is not applicable to dates that are stored
      // as date-only.
      $this->calculateOffset = FALSE;
    }
  }

  /**
   * {@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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Date::$calculateOffset protected property Determines if the timezone offset is calculated.
Date::buildOptionsForm public function Basic options for all sort criteria. Overrides SortPluginBase::buildOptionsForm
Date::defineOptions protected function Overrides SortPluginBase::defineOptions
Date::getDateField public function Override to account for dates stored as strings.
Date::getDateFormat public function Overridden in order to pass in the string date flag.
Date::query public function Called to add the sort to a query. Overrides SortPluginBase::query 1
Date::__construct public function
FieldAPIHandlerTrait::$entityFieldManager protected property The entity field manager.
FieldAPIHandlerTrait::$fieldDefinition protected property The field definition.
FieldAPIHandlerTrait::$fieldStorageDefinition protected property The field storage definition.
FieldAPIHandlerTrait::getEntityFieldManager protected function Returns the entity field manager.
FieldAPIHandlerTrait::getFieldDefinition protected function Gets the field definition.
FieldAPIHandlerTrait::getFieldStorageDefinition protected function Gets the field storage configuration.
SortPluginBase::adminSummary public function Display whether or not the sort order is ascending or descending.
SortPluginBase::buildExposeForm public function
SortPluginBase::canExpose public function Determine if a sort can be exposed.
SortPluginBase::defaultExposeOptions public function Provide default options for exposed sorts.
SortPluginBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts
SortPluginBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
SortPluginBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags
SortPluginBase::showExposeButton public function Shortcut to display the expose/hide button.
SortPluginBase::showSortForm protected function Shortcut to display the value form.
SortPluginBase::sortOptions protected function Provide a list of options for the default sort form.
SortPluginBase::sortSubmit public function
SortPluginBase::sortValidate protected function
SortPluginBase::submitOptionsForm public function Simple submit handler.
SortPluginBase::trustedCallbacks public static function
SortPluginBase::validateExposeForm public function Validate the options form.
SortPluginBase::validateOptionsForm public function Simple validate handler.