diff --git a/src/core/etl/src/Flow/ETL/Function/Cast.php b/src/core/etl/src/Flow/ETL/Function/Cast.php index 80d452bdb..d5b978da5 100644 --- a/src/core/etl/src/Flow/ETL/Function/Cast.php +++ b/src/core/etl/src/Flow/ETL/Function/Cast.php @@ -43,6 +43,10 @@ public function eval(Row $row) : mixed 'date' => match (\gettype($value)) { 'string' => (new \DateTimeImmutable($value))->setTime(0, 0, 0, 0), 'integer' => \DateTimeImmutable::createFromFormat('U', (string) $value), + 'object' => match ($value::class) { + \DateTime::class, \DateTimeImmutable::class => $value->setTime(0, 0, 0, 0), + default => null, + }, default => null, }, 'int', 'integer' => $caster->to(type_integer())->value($value), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CastTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CastTest.php index f6c0e4ab2..07fd025b6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CastTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CastTest.php @@ -42,6 +42,7 @@ public static function cast_provider() : array 'string_to_xml' => [$xmlString, 'xml', $xml], 'xml_to_string' => [$xml, 'string', $fullXMLString], 'datetime' => [new \DateTimeImmutable('2023-01-01 00:00:00 UTC'), 'string', '2023-01-01T00:00:00+00:00'], + 'datetime_to_date' => [new \DateTimeImmutable('2023-01-01 00:01:00 UTC'), 'date', new \DateTimeImmutable('2023-01-01T00:00:00+00:00')], 'uuid' => [Uuid::fromString('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'), 'string', 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'], 'bool_to_string' => [true, 'string', 'true'], ];