From a198a4eef46bd83a1952f8413077e721e5102f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 27 Feb 2023 23:13:06 +0100 Subject: [PATCH] fix: Avoid mutating the due date when calculating days MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/Card.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Db/Card.php b/lib/Db/Card.php index 5a80ed35a..e36a9fb0c 100644 --- a/lib/Db/Card.php +++ b/lib/Db/Card.php @@ -159,16 +159,17 @@ class Card extends RelationalEntity { } public function getDaysUntilDue(): ?int { - $today = new DateTime(); - $match_date = $this->getDuedate(); - if ($match_date === null) { + if ($this->getDuedate() === null) { return null; } + $today = new DateTime(); $today->setTime(0, 0); - $match_date->setTime(0, 0); - $diff = $today->diff($match_date); + $matchDate = DateTime::createFromInterface($this->getDuedate()); + $matchDate->setTime(0, 0); + + $diff = $today->diff($matchDate); return (int) $diff->format('%R%a'); // Extract days count in interval }