From de49d02990817f0fc2b1cc94dab797355ef6a252 Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 09:47:00 +0000
Subject: [PATCH 01/12] 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


From 249de42203a419ad7ec09fcc5e8d2ca57045da76 Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 10:02:09 +0000
Subject: [PATCH 02/12] updated as per phpcs and phpstan

---
 core/modules/views/src/Plugin/views/filter/Date.php | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index a76f377874dc..9a31ea1cf792 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -194,17 +194,9 @@ protected function opBetween($field) {
       // $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");
 
-- 
GitLab


From 77db46944fb8b37a60065cf1502bd1e16c58317c Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 10:05:57 +0000
Subject: [PATCH 03/12] updated again as per phpcs and phpstan

---
 core/modules/views/src/Plugin/views/filter/Date.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index 9a31ea1cf792..3a8471dc839e 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -217,7 +217,7 @@ protected function opSimple($field) {
   }
 
   /**
-   *
+   *Get Current_Time
    */
   public function getCurrentTime() {
     return time();
-- 
GitLab


From 8f03e349f27f46ead0f1f78b010c36c7b56ab1a2 Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 10:10:05 +0000
Subject: [PATCH 04/12] changed the code  as per phpcs and phpstan

---
 core/modules/views/src/Plugin/views/filter/Date.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index 3a8471dc839e..bf8becc79738 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -4,7 +4,6 @@
 
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\views\Attribute\ViewsFilter;
-use Drupal\Component\Datetime;
 
 /**
  * Filter to handle dates stored as a timestamp.
@@ -217,7 +216,7 @@ protected function opSimple($field) {
   }
 
   /**
-   *Get Current_Time
+   * Get Current_Time.
    */
   public function getCurrentTime() {
     return time();
-- 
GitLab


From 42a7fcd55fb01e8ca7693cc8468617797b1d2f21 Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 10:19:28 +0000
Subject: [PATCH 05/12] changed the code  as per phpstan

---
 core/modules/views/src/Plugin/views/filter/Date.php | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index bf8becc79738..02d373089895 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -217,6 +217,8 @@ protected function opSimple($field) {
 
   /**
    * Get Current_Time.
+   *
+   * @return int
    */
   public function getCurrentTime() {
     return time();
-- 
GitLab


From 9ee9f728f09de410385c42e4da6f6b05e2799252 Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 09:47:00 +0000
Subject: [PATCH 06/12] 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


From b04abd75df1630fc2bc1141c799503ef18914db8 Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 10:02:09 +0000
Subject: [PATCH 07/12] updated as per phpcs and phpstan

---
 core/modules/views/src/Plugin/views/filter/Date.php | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index a76f377874dc..9a31ea1cf792 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -194,17 +194,9 @@ protected function opBetween($field) {
       // $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");
 
-- 
GitLab


From c5a14922b018a806dc5b1a66cb4f59a09006c9d8 Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 10:05:57 +0000
Subject: [PATCH 08/12] updated again as per phpcs and phpstan

---
 core/modules/views/src/Plugin/views/filter/Date.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index 9a31ea1cf792..3a8471dc839e 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -217,7 +217,7 @@ protected function opSimple($field) {
   }
 
   /**
-   *
+   *Get Current_Time
    */
   public function getCurrentTime() {
     return time();
-- 
GitLab


From 52d70e7fed3411b4370d63fb6479b4409d67c037 Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 10:10:05 +0000
Subject: [PATCH 09/12] changed the code  as per phpcs and phpstan

---
 core/modules/views/src/Plugin/views/filter/Date.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index 3a8471dc839e..bf8becc79738 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -4,7 +4,6 @@
 
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\views\Attribute\ViewsFilter;
-use Drupal\Component\Datetime;
 
 /**
  * Filter to handle dates stored as a timestamp.
@@ -217,7 +216,7 @@ protected function opSimple($field) {
   }
 
   /**
-   *Get Current_Time
+   * Get Current_Time.
    */
   public function getCurrentTime() {
     return time();
-- 
GitLab


From a45eecfd1b9bf1acc06f90f000e53eb1043713cd Mon Sep 17 00:00:00 2001
From: Niranjan Reddy Panem <niranjan.reddy@materialplus.io>
Date: Mon, 17 Feb 2025 10:19:28 +0000
Subject: [PATCH 10/12] changed the code  as per phpstan

---
 core/modules/views/src/Plugin/views/filter/Date.php | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index bf8becc79738..02d373089895 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -217,6 +217,8 @@ protected function opSimple($field) {
 
   /**
    * Get Current_Time.
+   *
+   * @return int
    */
   public function getCurrentTime() {
     return time();
-- 
GitLab


From 6f13070bc1ac3e9fc273453796b2de0e601b515d Mon Sep 17 00:00:00 2001
From: Riyas N R <riyas.nr@qed42.com>
Date: Mon, 3 Mar 2025 19:14:23 +0530
Subject: [PATCH 11/12] Issue #2842409: Date filter selecting the same day in
 between filter returns no results

---
 .../views/src/Plugin/views/filter/Date.php    | 35 +++++-----
 .../src/Functional/Handler/FilterDateTest.php | 69 +++++++++++++++++++
 2 files changed, 88 insertions(+), 16 deletions(-)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index 02d373089895..7cefab8a3738 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -21,6 +21,7 @@ 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;
   }
 
@@ -180,25 +181,36 @@ 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'] == 'date') {
+      // Check if the max value lacks a time component (i.e., user selected only a date).
+      if (date('H:i:s', strtotime($this->value['max'])) == '00:00:00') {
+        $b = intval(strtotime($this->value['max'] . ' +1 day', 0)) - 1;
+      }
+    }
+
     if ($this->value['type'] == 'offset') {
-      $request_time = $this->getCurrentTime();
       // Keep sign.
-      // $a = '***CURRENT_TIME***' . sprintf('%+d', $a);.
-      $a = $request_time + $a;
+      $a = '***CURRENT_TIME***' . sprintf('%+d', $a);
+      // Keep sign for max, store original for checking.
+      $b_original = $b; // Save the raw offset in seconds.
       // Keep sign.
-      // $b = '***CURRENT_TIME***' . sprintf('%+d', $b);.
-      $b = $request_time + $b;
+      $b = '***CURRENT_TIME***' . sprintf('%+d', $b);
+      // If min and max are the same and max has no time part (whole days only).
+      if ($this->value['min'] === $this->value['max'] && ($b_original % 86400 === 0)) {
+        // Convert offset to days.
+        $offset_days = intdiv($b_original, 86400);
+        // Set $b to the end of that day (23:59:59).
+        $b = '***CURRENT_TIME***' . sprintf('%+d', ($offset_days * 86400) + 86399);
+      }
     }
     // 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.
     $operator = strtoupper($this->operator);
     $this->query->addWhereExpression($this->options['group'], "$field $operator $a AND $b");
-
   }
 
   /**
@@ -215,13 +227,4 @@ protected function opSimple($field) {
     $this->query->addWhereExpression($this->options['group'], "$field $this->operator $value");
   }
 
-  /**
-   * Get Current_Time.
-   *
-   * @return int
-   */
-  public function getCurrentTime() {
-    return time();
-  }
-
 }
diff --git a/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php b/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php
index 5cb8d0cd51e3..3cc85d0ff25f 100644
--- a/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php
+++ b/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php
@@ -134,6 +134,42 @@ protected function _testOffset(): void {
       ['nid' => $this->nodes[3]->id()],
     ];
     $this->assertIdenticalResultset($view, $expected_result, $this->map);
+    $view->destroy();
+
+    // Test offset for between operator with same date offset.
+    $view->initHandlers();
+    $view->filter['created']->operator = 'between';
+    $view->filter['created']->value['type'] = 'offset';
+    $view->filter['created']->value['max'] = '+1 day';
+    $view->filter['created']->value['min'] = '+1 day';
+    $view->executeDisplay('default');
+    $expected_result = [
+      ['nid' => $this->nodes[3]->id()],
+    ];
+    $this->assertIdenticalResultset($view, $expected_result, $this->map);
+    $view->destroy();
+
+    // Test offset for between operator with time component.
+    $view->initHandlers();
+    $view->filter['created']->operator = 'between';
+    $view->filter['created']->value['type'] = 'offset';
+    $view->filter['created']->value['max'] = '+1 day 4 hours';
+    $view->filter['created']->value['min'] = '+1 day';
+    $view->executeDisplay('default');
+    $expected_result = [
+      ['nid' => $this->nodes[3]->id()],
+    ];
+    $this->assertIdenticalResultset($view, $expected_result, $this->map);
+    $view->destroy();
+
+     // Test offset for between operator with no result.
+    $view->initHandlers();
+    $view->filter['created']->operator = 'between';
+    $view->filter['created']->value['type'] = 'offset';
+    $view->filter['created']->value['max'] = '+1 day 12 hours';
+    $view->filter['created']->value['min'] = '+1 day 6 hours';
+    $view->executeDisplay('default');
+    $this->assertIdenticalResultset($view, [], $this->map);
   }
 
   /**
@@ -166,6 +202,39 @@ protected function _testBetween(): void {
     $this->assertIdenticalResultset($view, $expected_result, $this->map);
     $view->destroy();
 
+    // Test between with same min and max date.
+    $view->initHandlers();
+    $view->filter['created']->operator = 'between';
+    $view->filter['created']->value['min'] = '1970-01-03';
+    $view->filter['created']->value['max'] = '1970-01-03';
+    $view->executeDisplay('default');
+    $expected_result = [
+      ['nid' => $this->nodes[1]->id()],
+    ];
+    $this->assertIdenticalResultset($view, $expected_result, $this->map);
+    $view->destroy();
+
+    // Test between with same min and max date with time value.
+    $view->initHandlers();
+    $view->filter['created']->operator = 'between';
+    $view->filter['created']->value['min'] = '1970-01-03 12:00:00';
+    $view->filter['created']->value['max'] = '1970-01-03 18:00:00';
+    $view->executeDisplay('default');
+    $expected_result = [
+      ['nid' => $this->nodes[1]->id()],
+    ];
+    $this->assertIdenticalResultset($view, $expected_result, $this->map);
+    $view->destroy();
+
+    // Test between with same min and max date with no results.
+    $view->initHandlers();
+    $view->filter['created']->operator = 'between';
+    $view->filter['created']->value['min'] = '1970-01-03 12:00:00';
+    $view->filter['created']->value['max'] = '1970-01-03 16:00:00';
+    $view->executeDisplay('default');
+    $this->assertIdenticalResultset($view, [], $this->map);
+    $view->destroy();
+
     // Test not between with min and max.
     $view->initHandlers();
     $view->filter['created']->operator = 'not between';
-- 
GitLab


From 07d7e90a50a7351c66136c6cef620e224277a143 Mon Sep 17 00:00:00 2001
From: Riyas N R <riyas.nr@qed42.com>
Date: Mon, 3 Mar 2025 19:26:20 +0530
Subject: [PATCH 12/12] Issue #2842409: Fix phpcs issue

---
 core/modules/views/src/Plugin/views/filter/Date.php             | 2 +-
 .../views/tests/src/Functional/Handler/FilterDateTest.php       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index 7cefab8a3738..7597f1873f22 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -195,7 +195,7 @@ protected function opBetween($field) {
       // Keep sign.
       $a = '***CURRENT_TIME***' . sprintf('%+d', $a);
       // Keep sign for max, store original for checking.
-      $b_original = $b; // Save the raw offset in seconds.
+      $b_original = $b;
       // Keep sign.
       $b = '***CURRENT_TIME***' . sprintf('%+d', $b);
       // If min and max are the same and max has no time part (whole days only).
diff --git a/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php b/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php
index 3cc85d0ff25f..ec5429d3128b 100644
--- a/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php
+++ b/core/modules/views/tests/src/Functional/Handler/FilterDateTest.php
@@ -162,7 +162,7 @@ protected function _testOffset(): void {
     $this->assertIdenticalResultset($view, $expected_result, $this->map);
     $view->destroy();
 
-     // Test offset for between operator with no result.
+    // Test offset for between operator with no result.
     $view->initHandlers();
     $view->filter['created']->operator = 'between';
     $view->filter['created']->value['type'] = 'offset';
-- 
GitLab