translator = $translator; } public function getLabel($header): callable { return function ($value) use ($header) { if ('_header' === $value) { return $this->translator->trans($header); } if (null === $value) { return ''; } // 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; }; } }