From 46d3199eb8105c82f88a23daa9c786413e625644 Mon Sep 17 00:00:00 2001 From: David Tahir Date: Sat, 11 Dec 2021 06:30:32 +0100 Subject: [PATCH 1/5] fix #147 --- lib/Controller/AjaxController.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/Controller/AjaxController.php b/lib/Controller/AjaxController.php index f5dbd38..04b02af 100644 --- a/lib/Controller/AjaxController.php +++ b/lib/Controller/AjaxController.php @@ -1245,18 +1245,26 @@ public function getGoals(){ foreach($intervals as $interval){ $workedInInterval = 0; foreach($repItems as $repItem) { - if ($interval == $repItem->time) { - $workedInInterval = $repItem->totalDuration; - break; - } + + if ($goal->interval == 'Weekly'){ + if ($interval == $this->getStartOfWeek($repItem->time)->format('Y-m-d')) { + $workedInInterval = $repItem->totalDuration; + break; + } + } elseif ($goal->interval == 'Monthly'){ + if ($interval == $this->getStartOfMonth($repItem->time)->format('Y-m')) { + $workedInInterval = $repItem->totalDuration; + break; + } + } } $debtSeconds += ($goal->hours*3600 - $workedInInterval); } foreach($repItems as $period){ - if ($goal->interval == 'Weekly' && $period->time == $weekStart){ + if ($goal->interval == 'Weekly' && $this->getStartOfWeek($period->time)->format('Y-m-d') == $weekStart){ $workedSecondsCurrentPeriod += $period->totalDuration; - } elseif ($goal->interval == 'Monthly' && $period->time == $monthStart){ + } elseif ($goal->interval == 'Monthly' && $this->getStartOfMonth($period->time)->format('Y-m') == $monthStart){ $workedSecondsCurrentPeriod += $period->totalDuration; } } From eedc0114601f8e6647268b4021c0375bd32de06c Mon Sep 17 00:00:00 2001 From: David Tahir Date: Thu, 6 Jan 2022 09:11:26 +0100 Subject: [PATCH 2/5] reset time for startOfWeek and startOfMonth --- lib/Controller/AjaxController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Controller/AjaxController.php b/lib/Controller/AjaxController.php index 04b02af..80ff6d6 100644 --- a/lib/Controller/AjaxController.php +++ b/lib/Controller/AjaxController.php @@ -1180,6 +1180,7 @@ public function getStartOfWeek($timestamp){ $weeknumber = $date->format("W"); $year = $date->format("Y"); $weekstartdt = new \DateTime(); + $weekstartdt->setTime(0, 0, 0, 0); $weekstartdt->setISODate($year, $weeknumber); return $weekstartdt; @@ -1187,6 +1188,7 @@ public function getStartOfWeek($timestamp){ public function getStartOfMonth($timestamp){ $date = new \DateTime('@'.$timestamp); $date->modify('first day of this month'); + $date->setTime(0, 0, 0, 0); return $date; } From 2e13dbaabe70eed4357c6c424e9924881e33ca2d Mon Sep 17 00:00:00 2001 From: David Tahir Date: Sun, 9 Jan 2022 15:56:02 +0100 Subject: [PATCH 3/5] include current week in calculation --- lib/Controller/AjaxController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Controller/AjaxController.php b/lib/Controller/AjaxController.php index 80ff6d6..8c54caa 100644 --- a/lib/Controller/AjaxController.php +++ b/lib/Controller/AjaxController.php @@ -1199,7 +1199,7 @@ public function getWeeksSince($timestamp){ $oneWeek = \DateInterval::createFromDateString('1 week'); $currentWeek = $start; $weeks = []; - while ($currentWeek < $end){ + while ($currentWeek <= $end){ $weeks[] = $currentWeek->format("Y-m-d"); $currentWeek->add($oneWeek); } @@ -1211,7 +1211,7 @@ public function getMonthsSince($timestamp){ $oneMonth = \DateInterval::createFromDateString('1 month'); $currentMonth = $start; $months = []; - while ($currentMonth < $end){ + while ($currentMonth <= $end){ $months[] = $currentMonth->format("Y-m"); $currentMonth->add($oneMonth); } From 2aceddd1192e7408afd847c9577c1db27c68fd4c Mon Sep 17 00:00:00 2001 From: David Tahir Date: Sun, 9 Jan 2022 16:02:52 +0100 Subject: [PATCH 4/5] revert time calucation --- lib/Controller/AjaxController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Controller/AjaxController.php b/lib/Controller/AjaxController.php index 8c54caa..80ff6d6 100644 --- a/lib/Controller/AjaxController.php +++ b/lib/Controller/AjaxController.php @@ -1199,7 +1199,7 @@ public function getWeeksSince($timestamp){ $oneWeek = \DateInterval::createFromDateString('1 week'); $currentWeek = $start; $weeks = []; - while ($currentWeek <= $end){ + while ($currentWeek < $end){ $weeks[] = $currentWeek->format("Y-m-d"); $currentWeek->add($oneWeek); } @@ -1211,7 +1211,7 @@ public function getMonthsSince($timestamp){ $oneMonth = \DateInterval::createFromDateString('1 month'); $currentMonth = $start; $months = []; - while ($currentMonth <= $end){ + while ($currentMonth < $end){ $months[] = $currentMonth->format("Y-m"); $currentMonth->add($oneMonth); } From 29b98f3f7bda2d0907b6a23887a3345ea3a1518f Mon Sep 17 00:00:00 2001 From: David Tahir Date: Mon, 10 Jan 2022 14:07:02 +0100 Subject: [PATCH 5/5] allow mutliple repItems for one goal in each interval --- lib/Controller/AjaxController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Controller/AjaxController.php b/lib/Controller/AjaxController.php index 80ff6d6..15a5fcb 100644 --- a/lib/Controller/AjaxController.php +++ b/lib/Controller/AjaxController.php @@ -1243,19 +1243,18 @@ public function getGoals(){ } $workedSecondsCurrentPeriod = 0; $debtSeconds = 0; - array_pop($intervals); foreach($intervals as $interval){ $workedInInterval = 0; foreach($repItems as $repItem) { if ($goal->interval == 'Weekly'){ if ($interval == $this->getStartOfWeek($repItem->time)->format('Y-m-d')) { - $workedInInterval = $repItem->totalDuration; + $workedInInterval += $repItem->totalDuration; break; } } elseif ($goal->interval == 'Monthly'){ if ($interval == $this->getStartOfMonth($repItem->time)->format('Y-m')) { - $workedInInterval = $repItem->totalDuration; + $workedInInterval += $repItem->totalDuration; break; } }