Add getDueDateTime function to expose the duedate in datetime format.

Signed-off-by: Raul <raul@nextcloud.com>
This commit is contained in:
Raul
2022-05-04 17:44:25 +02:00
parent ebbafbe55d
commit 9369a697e3
2 changed files with 11 additions and 8 deletions

View File

@@ -125,15 +125,18 @@ class Card extends RelationalEntity {
$this->databaseType = $type; $this->databaseType = $type;
} }
public function getDuedate($isoFormat = false) { public function getDueDateTime(): ?DateTime {
if ($this->duedate === null) { return $this->duedate ? new DateTime($this->duedate) : null;
return null;
} }
$dt = new DateTime($this->duedate);
public function getDuedate($isoFormat = false): ?string {
$dt = $this->getDueDateTime();
$format = 'c';
if (!$isoFormat && $this->databaseType === 'mysql') { 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 { public function getCalendarObject(): VCalendar {

View File

@@ -59,7 +59,7 @@ class CardDetails extends Card
$today = new DateTime(); $today = new DateTime();
$today->setTime(0, 0); $today->setTime(0, 0);
$match_date = new DateTime($this->getDuedate()); $match_date = $this->getDueDateTime() ?? new DateTime();
$match_date->setTime(0, 0); $match_date->setTime(0, 0);
$diff = $today->diff($match_date); $diff = $today->diff($match_date);