diff --git a/system/Entity/Entity.php b/system/Entity/Entity.php index 464992af6251..5473c621128d 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 \CodeIgniter\I18n\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..0d1bfc5d17ad 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->assertEquals('2022-11-11 11:11:11', $entity->toRawArray()['created_at']); + } + public function testFilledConstruction(): void { $data = [