Skip to content

Commit

Permalink
Merge pull request #699 from mickas/fix-datetime-serialization
Browse files Browse the repository at this point in the history
Fix \DateTime serialization of requests.
  • Loading branch information
jlevers committed May 18, 2024
2 parents 219f9e3 + cac5971 commit b94e575
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Traits/HasArrayableAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');
}
}

0 comments on commit b94e575

Please sign in to comment.