fix: Avoid mutating the due date when calculating days

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2023-02-27 23:13:06 +01:00
parent 2c96108b2e
commit a198a4eef4

View File

@@ -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
}