Correcciones

This commit is contained in:
Juan Pablo Vial
2025-03-03 21:41:43 -03:00
parent 5f69069aa0
commit aeeca65d94
9 changed files with 122 additions and 43 deletions

View File

@ -2,6 +2,7 @@
namespace Incoviba\Common\Implement\Repository\Mapper;
use DateTimeImmutable;
use DateMalformedStringException;
use Incoviba\Common\Implement\Repository\Mapper;
class DateTime extends Mapper
@ -9,7 +10,17 @@ class DateTime extends Mapper
public function __construct(string $column, ?string $property = null)
{
$this->setFunction(function($data) use ($column) {
return new DateTimeImmutable($data[$column] ?? '');
if (!isset($data[$column])) {
return null;
}
if (is_a($data[$column], DateTimeImmutable::class)) {
return $data[$column];
}
try {
return new DateTimeImmutable($data[$column] ?? '');
} catch (DateMalformedStringException) {
return new DateTimeImmutable();
}
});
if ($property !== null) {
$this->setProperty($property);