query modified_after in UTC (#5743)

This commit is contained in:
Kevin Papst
2025-12-24 16:33:28 +01:00
committed by GitHub
parent 3fcaf55d02
commit 806bb97e60
4 changed files with 12 additions and 16 deletions

View File

@@ -124,11 +124,6 @@ parameters:
count: 1 count: 1
path: src/API/TagController.php path: src/API/TagController.php
-
message: "#^Parameter \\#1 \\$datetime of method App\\\\Timesheet\\\\DateTimeFactory\\:\\:createDateTime\\(\\) expects string, mixed given\\.$#"
count: 3
path: src/API/TimesheetController.php
- -
message: "#^Parameter \\#2 \\$statistic of class App\\\\Event\\\\ActivityStatisticEvent constructor expects App\\\\Model\\\\ActivityStatistic, App\\\\Model\\\\ActivityStatistic\\|null given\\.$#" message: "#^Parameter \\#2 \\$statistic of class App\\\\Event\\\\ActivityStatisticEvent constructor expects App\\\\Model\\\\ActivityStatistic, App\\\\Model\\\\ActivityStatistic\\|null given\\.$#"
count: 1 count: 1

View File

@@ -93,7 +93,7 @@ final class TimesheetController extends BaseApiController
#[Rest\QueryParam(name: 'billable', requirements: '0|1', strict: true, nullable: true, description: 'Filter for non-/billable records. Allowed values: 0=non-billable, 1=billable (default: all)')] #[Rest\QueryParam(name: 'billable', requirements: '0|1', strict: true, nullable: true, description: 'Filter for non-/billable records. Allowed values: 0=non-billable, 1=billable (default: all)')]
#[Rest\QueryParam(name: 'full', requirements: '0|1|true|false', strict: true, nullable: true, description: 'Allows to fetch full objects including subresources. Allowed values: 0|1|false|true (default: false)')] #[Rest\QueryParam(name: 'full', requirements: '0|1|true|false', strict: true, nullable: true, description: 'Allows to fetch full objects including subresources. Allowed values: 0|1|false|true (default: false)')]
#[Rest\QueryParam(name: 'term', description: 'Free search term', nullable: true)] #[Rest\QueryParam(name: 'term', description: 'Free search term', nullable: true)]
#[Rest\QueryParam(name: 'modified_after', requirements: [new Constraints\DateTime(format: 'Y-m-d\TH:i:s')], strict: true, nullable: true, description: 'Only records changed after this date will be included (format: HTML5 datetime-local, e.g. YYYY-MM-DDThh:mm:ss)')] #[Rest\QueryParam(name: 'modified_after', requirements: [new Constraints\DateTime(format: 'Y-m-d\TH:i:s')], strict: true, nullable: true, description: 'Only records changed after this date will be included. You need to pass in a UTC date-time, as this field is stored in UTC (format: HTML5 datetime-local, e.g. YYYY-MM-DDThh:mm:ss)')]
public function cgetAction(ParamFetcherInterface $paramFetcher, CustomerRepository $customerRepository, ProjectRepository $projectRepository, ActivityRepository $activityRepository, UserRepository $userRepository): Response public function cgetAction(ParamFetcherInterface $paramFetcher, CustomerRepository $customerRepository, ProjectRepository $projectRepository, ActivityRepository $activityRepository, UserRepository $userRepository): Response
{ {
$query = new TimesheetQuery(false); $query = new TimesheetQuery(false);
@@ -228,8 +228,9 @@ final class TimesheetController extends BaseApiController
$query->setSearchTerm(new SearchTerm($term)); $query->setSearchTerm(new SearchTerm($term));
} }
if (!empty($modifiedAfter = $paramFetcher->get('modified_after'))) { $modifiedAfter = $paramFetcher->get('modified_after');
$query->setModifiedAfter($factory->createDateTime($modifiedAfter)); if (\is_string($modifiedAfter)) {
$query->setModifiedAfter(new \DateTimeImmutable($modifiedAfter, new \DateTimeZone('UTC')));
} }
$data = $this->repository->getPagerfantaForQuery($query); $data = $this->repository->getPagerfantaForQuery($query);
@@ -392,7 +393,8 @@ final class TimesheetController extends BaseApiController
$limit = (int) $reqLimit; $limit = (int) $reqLimit;
} }
if (null !== ($reqBegin = $paramFetcher->get('begin'))) { $reqBegin = $paramFetcher->get('begin');
if (\is_string($reqBegin)) {
$begin = $this->getDateTimeFactory($user)->createDateTime($reqBegin); $begin = $this->getDateTimeFactory($user)->createDateTime($reqBegin);
} }
@@ -471,7 +473,8 @@ final class TimesheetController extends BaseApiController
$factory = $this->getDateTimeFactory(); $factory = $this->getDateTimeFactory();
$begin = $factory->createDateTime(); $begin = $factory->createDateTime();
if (null !== ($beginTmp = $paramFetcher->get('begin'))) { $beginTmp = $paramFetcher->get('begin');
if (\is_string($beginTmp)) {
$begin = $factory->createDateTime($beginTmp); $begin = $factory->createDateTime($beginTmp);
} }

View File

@@ -36,7 +36,7 @@ class TimesheetQuery extends ActivityQuery implements BillableInterface, DateRan
private int $state = self::STATE_ALL; private int $state = self::STATE_ALL;
private int $exported = self::STATE_ALL; private int $exported = self::STATE_ALL;
private ?int $maxResults = null; private ?int $maxResults = null;
private ?\DateTime $modifiedAfter = null; private ?\DateTimeInterface $modifiedAfter = null;
/** /**
* @var array<Tag> * @var array<Tag>
*/ */
@@ -244,15 +244,13 @@ class TimesheetQuery extends ActivityQuery implements BillableInterface, DateRan
$this->tags[$tag->getId()] = $tag; $this->tags[$tag->getId()] = $tag;
} }
public function getModifiedAfter(): ?\DateTime public function getModifiedAfter(): ?\DateTimeInterface
{ {
return $this->modifiedAfter; return $this->modifiedAfter;
} }
public function setModifiedAfter(\DateTime $modifiedAfter): TimesheetQuery public function setModifiedAfter(\DateTimeInterface $modifiedAfter): void
{ {
$this->modifiedAfter = $modifiedAfter; $this->modifiedAfter = $modifiedAfter;
return $this;
} }
} }

View File

@@ -169,7 +169,7 @@ class TimesheetQueryTest extends BaseQueryTest
self::assertNull($sut->getModifiedAfter()); self::assertNull($sut->getModifiedAfter());
$date = new \DateTime('-3 hours'); $date = new \DateTime('-3 hours');
self::assertInstanceOf(TimesheetQuery::class, $sut->setModifiedAfter($date)); $sut->setModifiedAfter($date);
self::assertNotNull($sut->getModifiedAfter()); // just here to fix a PHPStan issue self::assertNotNull($sut->getModifiedAfter()); // just here to fix a PHPStan issue
self::assertSame($date, $sut->getModifiedAfter()); self::assertSame($date, $sut->getModifiedAfter());
} }