From f10aad927fc76171d06b1d4a3f3f86fc48a8580d Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 5 May 2021 13:02:09 +0200 Subject: [PATCH] fix timesheet collection fetch via API with end datetime set (#2552) --- src/API/TimesheetController.php | 2 +- src/Form/Model/DateRange.php | 14 ++++++++++++-- src/Repository/Query/TimesheetQuery.php | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/API/TimesheetController.php b/src/API/TimesheetController.php index 15103569..fd0d4477 100644 --- a/src/API/TimesheetController.php +++ b/src/API/TimesheetController.php @@ -138,7 +138,7 @@ class TimesheetController extends BaseApiController */ public function cgetAction(ParamFetcherInterface $paramFetcher): Response { - $query = new TimesheetQuery(); + $query = new TimesheetQuery(false); $query->setUser($this->getUser()); if ($this->isGranted('view_other_timesheet') && null !== ($user = $paramFetcher->get('user'))) { diff --git a/src/Form/Model/DateRange.php b/src/Form/Model/DateRange.php index b7710fc4..01a674ec 100644 --- a/src/Form/Model/DateRange.php +++ b/src/Form/Model/DateRange.php @@ -13,9 +13,15 @@ use DateTime; final class DateRange { + private $resetTimes; private $begin; private $end; + public function __construct(bool $resetTimes = true) + { + $this->resetTimes = $resetTimes; + } + public function getBegin(): ?DateTime { return $this->begin; @@ -24,7 +30,9 @@ final class DateRange public function setBegin(DateTime $begin): DateRange { $this->begin = $begin; - $this->begin->setTime(0, 0, 0); + if ($this->resetTimes) { + $this->begin->setTime(0, 0, 0); + } return $this; } @@ -37,7 +45,9 @@ final class DateRange public function setEnd(DateTime $end): DateRange { $this->end = $end; - $this->end->setTime(23, 59, 59); + if ($this->resetTimes) { + $this->end->setTime(23, 59, 59); + } return $this; } diff --git a/src/Repository/Query/TimesheetQuery.php b/src/Repository/Query/TimesheetQuery.php index 2ed4ed66..9266c55c 100644 --- a/src/Repository/Query/TimesheetQuery.php +++ b/src/Repository/Query/TimesheetQuery.php @@ -59,13 +59,13 @@ class TimesheetQuery extends ActivityQuery implements BillableInterface */ private $users = []; - public function __construct() + public function __construct(bool $resetTimes = true) { parent::__construct(); $this->setDefaults([ 'order' => self::ORDER_DESC, 'orderBy' => 'begin', - 'dateRange' => new DateRange() + 'dateRange' => new DateRange($resetTimes) ]); }