From 812bafaeae5b83136a4cfc77e2d5d1f873e316ea Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 14 Dec 2023 12:04:08 +0100 Subject: [PATCH 1/8] MergeRequests::all: send datetimes with microsecond precision --- src/Api/MergeRequests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index ed3779f6..23c5a1df 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -74,7 +74,7 @@ public function all($project_id = null, array $parameters = []) { $resolver = $this->createOptionsResolver(); $datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string { - return $value->format('c'); + return $value->format('c.u'); }; $resolver->setDefined('iids') ->setAllowedTypes('iids', 'array') From a20255a054225058eeade75a2e806e2a39b7e8e8 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 14 Dec 2023 15:14:18 +0100 Subject: [PATCH 2/8] Fix format - 2023-01-24T18:05:25.801Z works - 2023-01-24T18:05:25.801+00:00 does not work --- src/Api/MergeRequests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index 23c5a1df..ecb0260e 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -74,7 +74,7 @@ public function all($project_id = null, array $parameters = []) { $resolver = $this->createOptionsResolver(); $datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string { - return $value->format('c.u'); + return $value->format('Y-m-d\TH:i:s.vp'); }; $resolver->setDefined('iids') ->setAllowedTypes('iids', 'array') From 70c01815fbd5dc5f363adb78915a0dbb15bc4ab3 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 14 Dec 2023 15:42:14 +0100 Subject: [PATCH 3/8] Ensure UTC timezone is used --- src/Api/MergeRequests.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index ecb0260e..1b832fd7 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -74,7 +74,8 @@ public function all($project_id = null, array $parameters = []) { $resolver = $this->createOptionsResolver(); $datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string { - return $value->format('Y-m-d\TH:i:s.vp'); + $utc = \DateTimeImmutable::createFromInterface($value)->setTimezone(new \DateTimeZone('UTC')); + return $utc->format('Y-m-d\TH:i:s.v\Z'); }; $resolver->setDefined('iids') ->setAllowedTypes('iids', 'array') From 84b2a404be788ead8af1218ab8356c580b006207 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 14 Dec 2023 15:59:38 +0100 Subject: [PATCH 4/8] Adjust test --- tests/Api/MergeRequestsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Api/MergeRequestsTest.php b/tests/Api/MergeRequestsTest.php index ae8225bc..bfc5a123 100644 --- a/tests/Api/MergeRequestsTest.php +++ b/tests/Api/MergeRequestsTest.php @@ -110,8 +110,8 @@ public function shouldGetAllWithDateTimeParams(): void $createdBefore = new \DateTime('2018-01-31 00:00:00'); $expectedWithArray = [ - 'created_after' => $createdAfter->format(\DATE_ATOM), - 'created_before' => $createdBefore->format(\DATE_ATOM), + 'created_after' => '2018-01-01T00:00:00.000Z', + 'created_before' => '2018-01-01T00:00:00.000Z', ]; $api = $this->getApiMock(); From 4f63bbde5d3e0368ff44aca5206bd88a5d89fe48 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 14 Dec 2023 16:01:05 +0100 Subject: [PATCH 5/8] Fix typo --- tests/Api/MergeRequestsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Api/MergeRequestsTest.php b/tests/Api/MergeRequestsTest.php index bfc5a123..37662af0 100644 --- a/tests/Api/MergeRequestsTest.php +++ b/tests/Api/MergeRequestsTest.php @@ -111,7 +111,7 @@ public function shouldGetAllWithDateTimeParams(): void $expectedWithArray = [ 'created_after' => '2018-01-01T00:00:00.000Z', - 'created_before' => '2018-01-01T00:00:00.000Z', + 'created_before' => '2018-01-31T00:00:00.000Z', ]; $api = $this->getApiMock(); From 58894a98f5029622173f3cd73e74f1fcdaf07c88 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 14 Dec 2023 16:05:18 +0100 Subject: [PATCH 6/8] Fix for old PHP, improve test --- src/Api/MergeRequests.php | 2 +- tests/Api/MergeRequestsTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index 1b832fd7..32ff0cf2 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -74,7 +74,7 @@ public function all($project_id = null, array $parameters = []) { $resolver = $this->createOptionsResolver(); $datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string { - $utc = \DateTimeImmutable::createFromInterface($value)->setTimezone(new \DateTimeZone('UTC')); + $utc = (new \DateTimeImmutable($value->format(\DateTimeImmutable::RFC3339_EXTENDED)))->setTimezone(new \DateTimeZone('UTC')); return $utc->format('Y-m-d\TH:i:s.v\Z'); }; $resolver->setDefined('iids') diff --git a/tests/Api/MergeRequestsTest.php b/tests/Api/MergeRequestsTest.php index 37662af0..27a814d1 100644 --- a/tests/Api/MergeRequestsTest.php +++ b/tests/Api/MergeRequestsTest.php @@ -107,11 +107,11 @@ public function shouldGetAllWithDateTimeParams(): void $expectedArray = $this->getMultipleMergeRequestsData(); $createdAfter = new \DateTime('2018-01-01 00:00:00'); - $createdBefore = new \DateTime('2018-01-31 00:00:00'); + $createdBefore = new \DateTime('2018-01-31 12:00:00+03:00'); $expectedWithArray = [ 'created_after' => '2018-01-01T00:00:00.000Z', - 'created_before' => '2018-01-31T00:00:00.000Z', + 'created_before' => '2018-01-31T09:00:00.000Z', ]; $api = $this->getApiMock(); From 2b02e88729560e804bbf3af91c9542b797d44717 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 14 Dec 2023 16:07:22 +0100 Subject: [PATCH 7/8] Fix cs --- src/Api/MergeRequests.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index 32ff0cf2..2bb8584a 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -75,6 +75,7 @@ public function all($project_id = null, array $parameters = []) $resolver = $this->createOptionsResolver(); $datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string { $utc = (new \DateTimeImmutable($value->format(\DateTimeImmutable::RFC3339_EXTENDED)))->setTimezone(new \DateTimeZone('UTC')); + return $utc->format('Y-m-d\TH:i:s.v\Z'); }; $resolver->setDefined('iids') From 330c842e6c6277edef25a1412f7207c43e0c2af0 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 14 Dec 2023 16:08:57 +0100 Subject: [PATCH 8/8] Use some milliseconds in test --- tests/Api/MergeRequestsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Api/MergeRequestsTest.php b/tests/Api/MergeRequestsTest.php index 27a814d1..227b89a0 100644 --- a/tests/Api/MergeRequestsTest.php +++ b/tests/Api/MergeRequestsTest.php @@ -107,11 +107,11 @@ public function shouldGetAllWithDateTimeParams(): void $expectedArray = $this->getMultipleMergeRequestsData(); $createdAfter = new \DateTime('2018-01-01 00:00:00'); - $createdBefore = new \DateTime('2018-01-31 12:00:00+03:00'); + $createdBefore = new \DateTime('2018-01-31 12:00:00.123+03:00'); $expectedWithArray = [ 'created_after' => '2018-01-01T00:00:00.000Z', - 'created_before' => '2018-01-31T09:00:00.000Z', + 'created_before' => '2018-01-31T09:00:00.123Z', ]; $api = $this->getApiMock();