translator->trans($header); } if (null === $value) { return ''; } if ($value instanceof \DateTimeInterface) { return $value; } // warning: won't work with DateTimeImmutable as we reset time a few lines later $date = \DateTime::createFromFormat('Y-m-d', $value); $hasTime = false; if (false === $date) { $date = \DateTime::createFromFormat('Y-m-d H:i:s', $value); $hasTime = true; } // check that the creation could occurs. if (false === $date) { throw new \Exception(sprintf('The value %s could not be converted to %s', $value, \DateTime::class)); } if (!$hasTime) { $date->setTime(0, 0, 0); } return $date; }; } }