Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PropertyHandler/DateTimeExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public function importValue(Deserializer $deserializer, Field $field, mixed $sou

public function canImport(Field $field, string $format): bool
{
return in_array($field->phpType, [DateTimeInterface::class, DateTime::class, DateTimeImmutable::class], true);
return is_a($field->phpType, DateTimeInterface::class, allow_string: true);
}
}
9 changes: 9 additions & 0 deletions tests/Records/DateTimeExtends.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Crell\Serde\Records;

use DateTime;

final class DateTimeExtends extends DateTime {}
11 changes: 11 additions & 0 deletions tests/Records/DateTimeExtendsExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Crell\Serde\Records;

final class DateTimeExtendsExample {
public function __construct(
public DateTimeExtends $extendsProperty,
) {}
}
7 changes: 7 additions & 0 deletions tests/SerdeTestCases.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use Crell\Serde\Records\ClassWithReducibleProperty;
use Crell\Serde\Records\CompoundTypes;
use Crell\Serde\Records\DateTimeExample;
use Crell\Serde\Records\DateTimeExtends;
use Crell\Serde\Records\DateTimeExtendsExample;
use Crell\Serde\Records\DateTimeInterfaceExample;
use Crell\Serde\Records\DictionaryKeyTypes;
use Crell\Serde\Records\Drupal\EmailItem;
Expand Down Expand Up @@ -345,6 +347,11 @@ public static function round_trip_examples(): iterable
interfaceProperty: new \DateTimeImmutable('2025-12-25 12:34:56.789'),
),
];
yield 'datetimeextends_type' => [
'data' => new DateTimeExtendsExample(
extendsProperty: new DateTimeExtends('2025-12-25 12:34:56.789'),
),
];
}

public static function value_object_flatten_examples(): \Generator
Expand Down