Skip to content

Commit

Permalink
fix: recover the string type from Time.
Browse files Browse the repository at this point in the history
  • Loading branch information
ping-yee committed Nov 18, 2024
1 parent 27ae8bb commit b5b1d8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions system/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/system/Entity/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit b5b1d8d

Please sign in to comment.