From b5b1d8d45164b41c02caa13bdfb6de4a9b5e1edc Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Mon, 18 Nov 2024 17:49:13 +0800 Subject: [PATCH 1/3] fix: recover the string type from Time. --- system/Entity/Entity.php | 6 ++++++ tests/system/Entity/EntityTest.php | 9 +++++++++ 2 files changed, 15 insertions(+) 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 = [ From ce7b4ad387f148765dcffdef1384a310bb1de844 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Mon, 18 Nov 2024 17:54:12 +0800 Subject: [PATCH 2/3] style: cs-fix. --- tests/system/Entity/EntityTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Entity/EntityTest.php b/tests/system/Entity/EntityTest.php index 0d1bfc5d17ad..f749e2baaf22 100644 --- a/tests/system/Entity/EntityTest.php +++ b/tests/system/Entity/EntityTest.php @@ -971,7 +971,7 @@ public function testToRawArrayWithChangedDates(): void $entity->createdAt = '2022-11-11 11:11:11'; - $this->assertEquals('2022-11-11 11:11:11', $entity->toRawArray()['created_at']); + $this->assertSame('2022-11-11 11:11:11', $entity->toRawArray()['created_at']); } public function testFilledConstruction(): void From ac2712f6589e9cb1eb069ab12faa7d0a80cf1c7f Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Mon, 18 Nov 2024 18:09:17 +0800 Subject: [PATCH 3/3] style: fix the style. --- system/Entity/Entity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Entity/Entity.php b/system/Entity/Entity.php index 5473c621128d..7ba5e83bce06 100644 --- a/system/Entity/Entity.php +++ b/system/Entity/Entity.php @@ -237,7 +237,7 @@ public function toRawArray(bool $onlyChanged = false, bool $recursive = false): } foreach ($this->dates as $dateField) { - if (isset($this->attributes[$dateField]) && $this->attributes[$dateField] instanceof \CodeIgniter\I18n\Time) { + if (isset($this->attributes[$dateField]) && $this->attributes[$dateField] instanceof Time) { $this->attributes[$dateField] = $this->attributes[$dateField]->toDateTimeString(); } }