Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Condition/BaseDateRangeConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CraftCms\Cms\Support\Url;
use DateTimeInterface;
use Exception;
use Illuminate\Support\Facades\Date;
use Illuminate\Validation\Rule;
use Override;

Expand Down Expand Up @@ -379,6 +380,12 @@ protected function matchValue(?DateTimeInterface $value): bool

private function _inclusiveEndDate(): DateTimeInterface
{
return DateTimeHelper::toDateTime($this->_endDate)->modify('+1 day');
$endDate = DateTimeHelper::toDateTime($this->_endDate);

if ($endDate === false) {
throw new Exception('Invalid end date.');
}

return Date::instance($endDate)->modify('+1 day');
}
}
4 changes: 2 additions & 2 deletions src/Support/DateTimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class DateTimeHelper
* @param bool $assumeSystemTimeZone Whether it should be assumed that the value was set in the system timezone if
* the timezone was not specified. If this is `false`, UTC will be assumed.
* @param bool $setToSystemTimeZone Whether to set the resulting DateTime object to the system timezone.
* @return DateTime|false The DateTime object, or `false` if $object could not be converted to one
* @return DateTimeInterface|false The DateTime object, or `false` if $object could not be converted to one
*
* @throws Exception
*/
public static function toDateTime(mixed $value, bool $assumeSystemTimeZone = false, bool $setToSystemTimeZone = true): DateTime|false
public static function toDateTime(mixed $value, bool $assumeSystemTimeZone = false, bool $setToSystemTimeZone = true): DateTimeInterface|false
{
if ($value instanceof DateTime) {
return $value;
Expand Down
Loading