From c53654e3fce845b01e8ef3e4176a519e28f90d60 Mon Sep 17 00:00:00 2001 From: larssandergreen Date: Sat, 1 Oct 2022 20:12:13 -0600 Subject: [PATCH] Handle all from and to relative dates --- Civi/Api4/Utils/FormattingUtil.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Civi/Api4/Utils/FormattingUtil.php b/Civi/Api4/Utils/FormattingUtil.php index c47468f0a3..7b66db6f73 100644 --- a/Civi/Api4/Utils/FormattingUtil.php +++ b/Civi/Api4/Utils/FormattingUtil.php @@ -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); -- 2.25.1