diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index 9e4eac33ed88..831fca5bc8f5 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -1822,6 +1822,7 @@ public static function relativeToAbsolute($relativeTerm, $unit) { $to['d'] = $now['mday']; $to['M'] = $now['mon']; $to['Y'] = $now['year']; + $to = self::intervalAdd('day', -1, $to); unset($from); break; diff --git a/tests/phpunit/CRM/Utils/DateTest.php b/tests/phpunit/CRM/Utils/DateTest.php index 630e897edf22..65afb0384ae4 100644 --- a/tests/phpunit/CRM/Utils/DateTest.php +++ b/tests/phpunit/CRM/Utils/DateTest.php @@ -304,4 +304,16 @@ public function testCustomFormatTs() { $this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%Y"), "2018"); } + /** + * Test Earlier Day Relative term to absolute + */ + public function testRelativeEarlierDay() { + $date = CRM_Utils_Date::relativeToAbsolute('earlier', 'day'); + + $this->assertEquals([ + 'from' => NULL, + 'to' => date('Ymd000000', strtotime('-1 day')), + ], $date); + } + }