From cac597140f68198a446f4d1136393c4f25f4d822 Mon Sep 17 00:00:00 2001 From: Michal Kasprzykowski Date: Sat, 27 Apr 2024 03:43:28 +0200 Subject: [PATCH] Fix \DateTime serialization of requests. Changed formatting from DateTime::RFC3339 ('Y-m-d\TH:i:sP') to ZULU ('Y-m-d\TH:i:s\Z') Fixes #698 --- src/Traits/HasArrayableAttributes.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Traits/HasArrayableAttributes.php b/src/Traits/HasArrayableAttributes.php index 6e669e3d2..c1ed3fe79 100644 --- a/src/Traits/HasArrayableAttributes.php +++ b/src/Traits/HasArrayableAttributes.php @@ -60,7 +60,7 @@ public function valueToArray(mixed $value, array|string $type): mixed if (is_null($value)) { return null; } elseif ($value instanceof DateTime) { - return $value->format(DateTime::RFC3339); + return $this->toZuluString($value); } elseif (is_string($type)) { if (class_exists($type)) { return $value->toArray(); @@ -86,4 +86,12 @@ public function valueToArray(mixed $value, array|string $type): mixed throw new InvalidAttributeTypeException("Unrecognized attribute type `$type`"); } + + private function toZuluString(\DateTime $dateTime) + { + $dt = clone $dateTime; + $dt->setTimezone(new \DateTimeZone("UTC")); + + return $dt->format('Y-m-d\TH:i:s\Z'); + } }