X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fdatetime%2Fsrc%2FPlugin%2Fviews%2Fsort%2FDate.php;fp=web%2Fcore%2Fmodules%2Fdatetime%2Fsrc%2FPlugin%2Fviews%2Fsort%2FDate.php;h=0049e867feb7a1681e716e8dc319cd00f4132805;hp=2c8338ad259945bc72f94278c3b2669a9995ca26;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/datetime/src/Plugin/views/sort/Date.php b/web/core/modules/datetime/src/Plugin/views/sort/Date.php index 2c8338ad2..0049e867f 100644 --- a/web/core/modules/datetime/src/Plugin/views/sort/Date.php +++ b/web/core/modules/datetime/src/Plugin/views/sort/Date.php @@ -2,6 +2,8 @@ namespace Drupal\datetime\Plugin\views\sort; +use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; +use Drupal\views\FieldAPIHandlerTrait; use Drupal\views\Plugin\views\sort\Date as NumericDate; /** @@ -14,12 +16,38 @@ use Drupal\views\Plugin\views\sort\Date as NumericDate; */ 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() { - // Return the real field, since it is already in string format. - return "$this->tableAlias.$this->realField"; + // 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); } /**