From de49d02990817f0fc2b1cc94dab797355ef6a252 Mon Sep 17 00:00:00 2001 From: Niranjan Reddy Panem Date: Mon, 17 Feb 2025 09:47:00 +0000 Subject: [PATCH] added the current timestamp to offsets for twice the same day issue --- .../views/src/Plugin/views/filter/Date.php | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php index 3725281cad2c..a76f377874dc 100644 --- a/core/modules/views/src/Plugin/views/filter/Date.php +++ b/core/modules/views/src/Plugin/views/filter/Date.php @@ -4,6 +4,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\views\Attribute\ViewsFilter; +use Drupal\Component\Datetime; /** * Filter to handle dates stored as a timestamp. @@ -21,7 +22,6 @@ protected function defineOptions() { // Value is already set up properly, we're just adding our new field to it. $options['value']['contains']['type']['default'] = 'date'; - return $options; } @@ -181,20 +181,33 @@ public function acceptExposedInput($input) { * {@inheritdoc} */ protected function opBetween($field) { + $a = intval(strtotime($this->value['min'], 0)); $b = intval(strtotime($this->value['max'], 0)); if ($this->value['type'] == 'offset') { + $request_time = $this->getCurrentTime(); // Keep sign. - $a = '***CURRENT_TIME***' . sprintf('%+d', $a); + // $a = '***CURRENT_TIME***' . sprintf('%+d', $a);. + $a = $request_time + $a; // Keep sign. - $b = '***CURRENT_TIME***' . sprintf('%+d', $b); + // $b = '***CURRENT_TIME***' . sprintf('%+d', $b);. + $b = $request_time + $b; } +<<<<<<< Updated upstream // This is safe because we are manually scrubbing the values. It is // necessary to do it this way because $a and $b are formulas when using an // offset. +======= + + /* + This is safe because we are manually scrubbing the values. + It is necessary to do it this way because $a and $b are formulas when using an offset. + */ +>>>>>>> Stashed changes $operator = strtoupper($this->operator); $this->query->addWhereExpression($this->options['group'], "$field $operator $a AND $b"); + } /** @@ -211,4 +224,11 @@ protected function opSimple($field) { $this->query->addWhereExpression($this->options['group'], "$field $this->operator $value"); } + /** + * + */ + public function getCurrentTime() { + return time(); + } + } -- GitLab