From a31f78d966338ddcb72544f224ce5405d998344b Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Tue, 2 Jan 2018 14:23:29 +0100 Subject: [PATCH] calculate duration for running entries on the fly --- src/TimesheetBundle/Entity/Timesheet.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/TimesheetBundle/Entity/Timesheet.php b/src/TimesheetBundle/Entity/Timesheet.php index ff56b389..e13143c6 100644 --- a/src/TimesheetBundle/Entity/Timesheet.php +++ b/src/TimesheetBundle/Entity/Timesheet.php @@ -151,7 +151,12 @@ class Timesheet */ public function getDuration() { - return $this->duration; + if ($this->duration !== 0 || $this->begin === null) { + return $this->duration; + } + + $current = new \DateTime(); + return $current->getTimestamp() - $this->begin->getTimestamp(); } /**