diff --git a/system/Entity/Entity.php b/system/Entity/Entity.php index 464992af6251..7ba5e83bce06 100644 --- a/system/Entity/Entity.php +++ b/system/Entity/Entity.php @@ -236,6 +236,12 @@ public function toRawArray(bool $onlyChanged = false, bool $recursive = false): }, $this->attributes); } + foreach ($this->dates as $dateField) { + if (isset($this->attributes[$dateField]) && $this->attributes[$dateField] instanceof Time) { + $this->attributes[$dateField] = $this->attributes[$dateField]->toDateTimeString(); + } + } + return $this->attributes; } diff --git a/tests/system/Entity/EntityTest.php b/tests/system/Entity/EntityTest.php index 8dd7ceac31fa..f749e2baaf22 100644 --- a/tests/system/Entity/EntityTest.php +++ b/tests/system/Entity/EntityTest.php @@ -965,6 +965,15 @@ public function testToRawArrayOnlyChanged(): void ], $result); } + public function testToRawArrayWithChangedDates(): void + { + $entity = $this->getEntity(); + + $entity->createdAt = '2022-11-11 11:11:11'; + + $this->assertSame('2022-11-11 11:11:11', $entity->toRawArray()['created_at']); + } + public function testFilledConstruction(): void { $data = [