From f4d7571c9e0957be50e05c8e5474c128aea3dbfd Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 21 Jul 2026 14:35:40 +0200 Subject: [PATCH] Fix that `MillisecondTimestamp` converts null to int --- src/Behavior/MillisecondTimestamp.php | 4 ++++ tests/MillisecondTimestampBehaviorTest.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/Behavior/MillisecondTimestamp.php b/src/Behavior/MillisecondTimestamp.php index 65d8033..76b818b 100644 --- a/src/Behavior/MillisecondTimestamp.php +++ b/src/Behavior/MillisecondTimestamp.php @@ -24,6 +24,10 @@ public function fromDb($value, $key, $context) public function toDb($value, $key, $context) { + if ($value === null) { + return null; + } + if (is_numeric($value)) { return (int) ($value * 1000.0); } diff --git a/tests/MillisecondTimestampBehaviorTest.php b/tests/MillisecondTimestampBehaviorTest.php index 38e9585..a1045e4 100644 --- a/tests/MillisecondTimestampBehaviorTest.php +++ b/tests/MillisecondTimestampBehaviorTest.php @@ -15,6 +15,11 @@ public function testFromDbReturnsNullWhenNullIsPassed() $this->assertNull((new MillisecondTimestamp([]))->fromDb(null, 'key', null)); } + public function testToDbReturnsNullWhenNullIsPassed() + { + $this->assertNull((new MillisecondTimestamp([]))->toDb(null, 'key', null)); + } + public function testToDbReturnsUtcTimestampWithNonUtcInput() { $sometime = DateTime::createFromFormat(