diff --git a/src/Casts/DateTimeInterfaceCast.php b/src/Casts/DateTimeInterfaceCast.php index 9230c8b3..3aa75ce5 100644 --- a/src/Casts/DateTimeInterfaceCast.php +++ b/src/Casts/DateTimeInterfaceCast.php @@ -39,9 +39,9 @@ protected function castValue( } // Truncate nanoseconds to microseconds (first 6 digits) - // Input: 2024-12-02T16:20:15.969827247Z - $value = preg_replace('/\.(\d{6})\d*Z$/', '.$1Z', $value); - // Output: 2024-12-02T16:20:15.969827Z + if (is_string($value)) { + $value = preg_replace('/\.(\d{6})\d*Z$/', '.$1Z', $value); + } /** @var DateTimeInterface|null $datetime */ $datetime = $formats diff --git a/tests/Casts/DateTimeInterfaceCastTest.php b/tests/Casts/DateTimeInterfaceCastTest.php index 9c4b2a75..5d4a0f60 100644 --- a/tests/Casts/DateTimeInterfaceCastTest.php +++ b/tests/Casts/DateTimeInterfaceCastTest.php @@ -23,7 +23,6 @@ public DateTimeImmutable $dateTimeImmutable; }; - expect( $caster->cast( FakeDataStructureFactory::property($class, 'carbon'),