diff --git a/lib/Db/Card.php b/lib/Db/Card.php index e6823b37b..5599aef76 100644 --- a/lib/Db/Card.php +++ b/lib/Db/Card.php @@ -125,15 +125,18 @@ class Card extends RelationalEntity { $this->databaseType = $type; } - public function getDuedate($isoFormat = false) { - if ($this->duedate === null) { - return null; - } - $dt = new DateTime($this->duedate); + public function getDueDateTime(): ?DateTime { + return $this->duedate ? new DateTime($this->duedate) : null; + } + + public function getDuedate($isoFormat = false): ?string { + $dt = $this->getDueDateTime(); + $format = 'c'; if (!$isoFormat && $this->databaseType === 'mysql') { - return $dt->format('Y-m-d H:i:s'); + $format = 'Y-m-d H:i:s'; } - return $dt->format('c'); + + return $dt ? $dt->format($format) : null; } public function getCalendarObject(): VCalendar { diff --git a/lib/Model/CardDetails.php b/lib/Model/CardDetails.php index 08da0ff67..57e246450 100644 --- a/lib/Model/CardDetails.php +++ b/lib/Model/CardDetails.php @@ -59,7 +59,7 @@ class CardDetails extends Card $today = new DateTime(); $today->setTime(0, 0); - $match_date = new DateTime($this->getDuedate()); + $match_date = $this->getDueDateTime() ?? new DateTime(); $match_date->setTime(0, 0); $diff = $today->diff($match_date);