Skip to content

Commit 9210914

Browse files
tchiotludohaphan
authored andcommitted
Handle Datetime serialization (#148)
1 parent 0a0b2ec commit 9210914

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Common/Resource/AbstractResource.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ public function serialize(): \stdClass
145145
$val = $this->{$name};
146146

147147
$fn = function ($val) {
148-
return ($val instanceof Serializable) ? $val->serialize() : $val;
148+
if ($val instanceof Serializable) {
149+
return $val->serialize();
150+
} elseif ($val instanceof \DateTimeImmutable) {
151+
return $val->format('c');
152+
} else {
153+
return $val;
154+
}
149155
};
150156

151157
if (is_array($val)) {

0 commit comments

Comments
 (0)