From c9014a27b2b763542f48d0e71ce81d3d973ea138 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Mon, 22 Aug 2022 17:22:13 +0300 Subject: [PATCH 1/2] Fix null in DateTime on PHP 8.1 --- helpers/CalendarUtils.php | 2 +- models/CalendarEntry.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helpers/CalendarUtils.php b/helpers/CalendarUtils.php index 63b12ecd..a538d74d 100644 --- a/helpers/CalendarUtils.php +++ b/helpers/CalendarUtils.php @@ -75,7 +75,7 @@ public static function parseDateTimeString($value, $timeValue = null, $timeForma $ts += static::parseTime($timeValue, $timeFormat); } - $date = new DateTime(null, new DateTimeZone('UTC')); + $date = new DateTime('now', new DateTimeZone('UTC')); $date->setTimestamp($ts); $result = DateTime::createFromFormat(static::DB_DATE_FORMAT, static::toDBDateFormat($date), static::getDateTimeZone($timeZone)); diff --git a/models/CalendarEntry.php b/models/CalendarEntry.php index 31d4468d..0bad227c 100644 --- a/models/CalendarEntry.php +++ b/models/CalendarEntry.php @@ -311,7 +311,7 @@ public function afterFind() */ public function validateEndTime($attribute, $params) { - if (new DateTime($this->start_datetime) >= new DateTime($this->end_datetime)) { + if (new DateTime($this->start_datetime ?? 'now') >= new DateTime($this->end_datetime ?? 'now')) { $this->addError($attribute, Yii::t('CalendarModule.base', "End time must be after start time!")); } } @@ -348,8 +348,8 @@ public function getSearchAttributes() public function beforeSave($insert) { - $start = new DateTime($this->start_datetime); - $end = new DateTime($this->end_datetime); + $start = new DateTime($this->start_datetime ?? 'now'); + $end = new DateTime($this->end_datetime ?? 'now'); // Make sure end and start time is set right for all_day events if ($this->all_day) { @@ -505,7 +505,7 @@ public function getTimezone() */ public function getStartDateTime() { - return new DateTime($this->start_datetime, CalendarUtils::getSystemTimeZone()); + return new DateTime($this->start_datetime ?? 'now', CalendarUtils::getSystemTimeZone()); } /** @@ -514,7 +514,7 @@ public function getStartDateTime() */ public function getEndDateTime() { - return new DateTime($this->end_datetime, CalendarUtils::getSystemTimeZone()); + return new DateTime($this->end_datetime ?? 'now', CalendarUtils::getSystemTimeZone()); } /** @@ -1004,6 +1004,6 @@ public function canInvite(?User $user = null): bool public function isPast(): bool { $timeZone = CalendarUtils::getEndTimeZone($this); - return new DateTime('now', $timeZone) > new DateTime($this->end_datetime, $timeZone); + return new DateTime('now', $timeZone) > new DateTime($this->end_datetime ?? 'now', $timeZone); } } From ec5b818149402e16c55a4bfbf95543fec9cb13a3 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Wed, 24 Aug 2022 06:35:32 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- docs/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8968f024..7c1c99ac 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog 1.2.6 (Unreleased) -------------------- - Fix #327: Don't send notifications for canceled event +- Fix #334: Fix null in DateTime on PHP 8.1 1.2.5 (July 15, 2022)