Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null in DateTime on PHP 8.1 #334

Merged
merged 2 commits into from
Aug 24, 2022
Merged
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
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);
}
}