From 0b46c1f29dddc2ee8b6e38095d5a662260f5a55f Mon Sep 17 00:00:00 2001
From: ebremner <ebremner@uwaterloo.ca>
Date: Mon, 26 Jul 2021 12:56:32 -0400
Subject: [PATCH] ISTWCMS-4917: updating dates to check for query parameter and
 return any dates greater than that parameter

---
 src/Service/UWService.php | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/Service/UWService.php b/src/Service/UWService.php
index f8216a8f..f109234a 100644
--- a/src/Service/UWService.php
+++ b/src/Service/UWService.php
@@ -607,13 +607,27 @@ class UWService implements UWServiceInterface {
       // Get all the dates.
       $dates = $node->$field_name->getValue();
 
+      // Get the date query parameter.
+      $date_parameter = \Drupal::request()->query->get('date');
+
+      // If there is a date query parameter, convert
+      // to timestamp so we can compare against dates
+      // in the event.  If there is no parameter, set
+      // the timestamp todays date.
+      if ($date_parameter) {
+        $check_date = strtotime($date_parameter['value']);
+      }
+      else {
+        $check_date = strtotime("now");
+      }
+
       // Step through each of the dates and get
       // out correct values.
       foreach ($dates as $date) {
 
-        // Ensure that the dates are greater than now, before
-        // adding it to the dates array.
-        if ($date['end_value'] > strtotime("now")) {
+        // Ensure that the dates are greater than timestamp
+        // that we generated above.
+        if ($date['end_value'] > $check_date) {
 
           // The all day case, duration is always 1439.
           if ($date['duration'] == '1439') {
-- 
GitLab