Skip to content

Commit b5b1d8d

Browse files
committed
fix: recover the string type from Time.
1 parent 27ae8bb commit b5b1d8d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

system/Entity/Entity.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ public function toRawArray(bool $onlyChanged = false, bool $recursive = false):
236236
}, $this->attributes);
237237
}
238238

239+
foreach ($this->dates as $dateField) {
240+
if (isset($this->attributes[$dateField]) && $this->attributes[$dateField] instanceof \CodeIgniter\I18n\Time) {
241+
$this->attributes[$dateField] = $this->attributes[$dateField]->toDateTimeString();
242+
}
243+
}
244+
239245
return $this->attributes;
240246
}
241247

tests/system/Entity/EntityTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,15 @@ public function testToRawArrayOnlyChanged(): void
965965
], $result);
966966
}
967967

968+
public function testToRawArrayWithChangedDates(): void
969+
{
970+
$entity = $this->getEntity();
971+
972+
$entity->createdAt = '2022-11-11 11:11:11';
973+
974+
$this->assertEquals('2022-11-11 11:11:11', $entity->toRawArray()['created_at']);
975+
}
976+
968977
public function testFilledConstruction(): void
969978
{
970979
$data = [

0 commit comments

Comments
 (0)