Handle all from and to relative dates
authorlarssandergreen <lars@wildsight.ca>
Sun, 2 Oct 2022 02:12:13 +0000 (20:12 -0600)
committerlarssandergreen <lars@wildsight.ca>
Sun, 2 Oct 2022 02:12:13 +0000 (20:12 -0600)
Civi/Api4/Utils/FormattingUtil.php

index c47468f0a30fe1c24fd3557298fae435a541ffb2..7b66db6f73061ea405c1f15a74c445e3f681d2f0 100644 (file)
@@ -159,9 +159,20 @@ class FormattingUtil {
       case 'LIKE':
       case 'NOT LIKE':
         $operator = ($operator === '=' || $operator === 'LIKE') ? 'BETWEEN' : 'NOT BETWEEN';
-        return [self::formatDateValue($format, $dateFrom), self::formatDateValue($format, $dateTo)];
 
-      // Less-than or greater-than-equal-to comparisons use the lower value
+        if (is_null($dateFrom) && !is_null($dateTo)) {
+          $operator = '<=';
+          return self::formatDateValue($format, $dateTo);
+        }
+        elseif (!is_null($dateFrom) && is_null($dateTo)) {
+          $operator = '>=';
+          return self::formatDateValue($format, $dateFrom);
+        }
+        else {
+          return [self::formatDateValue($format, $dateFrom), self::formatDateValue($format, $dateTo)];
+        }
+
+        // Less-than or greater-than-equal-to comparisons use the lower value
       case '<':
       case '>=':
         return self::formatDateValue($format, $dateFrom);