Skip to content

Commit

Permalink
Fixed casting DateTime objects into datetime/date (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech authored Mar 29, 2024
1 parent 94555e2 commit 0cf5840
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/etl/src/Flow/ETL/Function/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
Expand Down

0 comments on commit 0cf5840

Please sign in to comment.