Skip to content

Commit f70dc82

Browse files
author
Caitlin Bales (MSFT)
committed
PHP fix to serialize DateTime to RFC3339 format
1 parent 5edebe7 commit f70dc82

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Templates/PHP/Model/EntityType.php.tt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,19 @@ if (property.Type.GetTypeString()[0] == '\\') { #>
256256

257257
/**
258258
* Serializes the object by property array
259+
* Manually serialize DateTime into RFC3339 format
259260
*
260261
* @return array The list of properties
261262
*/
262263
public function jsonSerialize()
263264
{
264-
return $this->getProperties();
265+
$serializableProperties = $this->getProperties();
266+
foreach ($serializableProperties as $property => $val) {
267+
if (is_a($val, "\DateTime")) {
268+
$serializableProperties[$property] = $val->format(\DateTime::RFC3339);
269+
}
270+
}
271+
return $serializableProperties;
265272
}
266273
<#
267274
}

0 commit comments

Comments
 (0)