Skip to content

Commit

Permalink
Merge pull request #334 from humhub/fix/php-81
Browse files Browse the repository at this point in the history
Fix null in DateTime on PHP 8.1
  • Loading branch information
luke- authored Aug 24, 2022
2 parents b9d9840 + ec5b818 commit 695cf6e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion helpers/CalendarUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
12 changes: 6 additions & 6 deletions models/CalendarEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!"));
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 695cf6e

Please sign in to comment.