From 7575bd0bf75761e408ee191094b4a9014727dc38 Mon Sep 17 00:00:00 2001 From: Raul Date: Mon, 9 May 2022 14:44:36 +0200 Subject: [PATCH] Fix due status calculation Signed-off-by: Raul --- lib/Db/Card.php | 9 ++++++--- lib/Model/BoardSummary.php | 5 ++--- lib/Model/CardDetails.php | 17 ++++++++--------- lib/Service/OverviewService.php | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/Db/Card.php b/lib/Db/Card.php index b866fd3e3..5a80ed35a 100644 --- a/lib/Db/Card.php +++ b/lib/Db/Card.php @@ -158,11 +158,14 @@ class Card extends RelationalEntity { return $calendar; } - public function getDaysUntilDue(): int { + public function getDaysUntilDue(): ?int { $today = new DateTime(); - $today->setTime(0, 0); + $match_date = $this->getDuedate(); + if ($match_date === null) { + return null; + } - $match_date = $this->getDueDateTime() ?? new DateTime(); + $today->setTime(0, 0); $match_date->setTime(0, 0); $diff = $today->diff($match_date); diff --git a/lib/Model/BoardSummary.php b/lib/Model/BoardSummary.php index 2fa827a3b..365a454c0 100644 --- a/lib/Model/BoardSummary.php +++ b/lib/Model/BoardSummary.php @@ -24,8 +24,7 @@ namespace OCA\Deck\Model; use OCA\Deck\Db\Board; -class BoardSummary extends Board -{ +class BoardSummary extends Board { private Board $board; public function __construct(Board $board) { @@ -42,7 +41,7 @@ class BoardSummary extends Board protected function getter($name) { return $this->board->getter($name); - } + } public function __call($name, $arguments) { return $this->board->__call($name, $arguments); diff --git a/lib/Model/CardDetails.php b/lib/Model/CardDetails.php index 8f80e5866..d894c274e 100644 --- a/lib/Model/CardDetails.php +++ b/lib/Model/CardDetails.php @@ -25,8 +25,7 @@ namespace OCA\Deck\Model; use OCA\Deck\Db\Board; use OCA\Deck\Db\Card; -class CardDetails extends Card -{ +class CardDetails extends Card { private Card $card; private ?Board $board; @@ -60,18 +59,18 @@ class CardDetails extends Card private function getDueStatus(): int { $diffDays = $this->getDaysUntilDue(); + if ($diffDays === null || $diffDays > 1) { + return static::DUEDATE_FUTURE; + } if ($diffDays === 1) { return static::DUEDATE_NEXT; } if ($diffDays === 0) { return static::DUEDATE_NOW; } - if ($diffDays < 0) { - return static::DUEDATE_OVERDUE; - } - return static::DUEDATE_FUTURE; - } + return static::DUEDATE_OVERDUE; + } private function appendBoardDetails(&$array): void { if (!$this->board) { @@ -83,8 +82,8 @@ class CardDetails extends Card } protected function getter($name) { - return $this->card->getter($name); - } + return $this->card->getter($name); + } public function __call($name, $arguments) { return $this->card->__call($name, $arguments); } diff --git a/lib/Service/OverviewService.php b/lib/Service/OverviewService.php index f45f22f33..8b8b07511 100644 --- a/lib/Service/OverviewService.php +++ b/lib/Service/OverviewService.php @@ -108,7 +108,7 @@ class OverviewService { $diffDays = $card->getDaysUntilDue(); $key = 'later'; - if ($card->getDuedate() === null) { + if ($diffDays === null) { $key = 'nodue'; } elseif ($diffDays < 0) { $key = 'overdue';