From 0864918e8b80813680ecc91a873eb46902a99076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tony=20Vl=C4=8Dek?= Date: Fri, 29 Sep 2023 16:32:14 +0200 Subject: [PATCH] fix: Formatting of publishTime date string when none given Use ISO8601 format when the publishTime is not provided in the message. --- src/LegacyEventMapper.php | 2 +- tests/LegacyEventMapperTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/LegacyEventMapper.php b/src/LegacyEventMapper.php index 77f57a2a..cb452d02 100644 --- a/src/LegacyEventMapper.php +++ b/src/LegacyEventMapper.php @@ -193,7 +193,7 @@ private function convertRawPubsubPayload(array $jsonData, string $requestUriPath if (array_key_exists('publishTime', $jsonData['message'])) { $timestamp = $jsonData['message']['publishTime']; } else { - $timestamp = gmdate('%Y-%m-%dT%H:%M:%S.%6NZ'); + $timestamp = gmdate('Y-m-d\TH:i:s.v\Z'); } return [ diff --git a/tests/LegacyEventMapperTest.php b/tests/LegacyEventMapperTest.php index 2a3dda7d..00511757 100644 --- a/tests/LegacyEventMapperTest.php +++ b/tests/LegacyEventMapperTest.php @@ -128,7 +128,7 @@ public function testRawPubsubNoPath(): void ); $this->assertNull($cloudevent->getSubject()); $this->assertEqualsWithDelta( - strtotime(gmdate('%Y-%m-%dT%H:%M:%S.%6NZ')), + strtotime(gmdate('Y-m-d\TH:i:s.v\Z')), strtotime($cloudevent->getTime()), 1 ); @@ -168,7 +168,7 @@ public function testRawPubsubWithPath(): void ); $this->assertNull($cloudevent->getSubject()); $this->assertEqualsWithDelta( - strtotime(gmdate('%Y-%m-%dT%H:%M:%S.%6NZ')), + strtotime(gmdate('Y-m-d\TH:i:s.v\Z')), strtotime($cloudevent->getTime()), 1 );