public function transform($dateTime)
{
if ($dateTime === null) {
return '';
}
if (!$dateTime instanceof \DateTime) {
throw new \InvalidArgumentException('Expected value of type \DateTime');
}
$inputTimezone = $this->getOption('input_timezone');
// convert time to UTC before passing it to the formatter
if ($inputTimezone != 'UTC') {
$dateTime->setTimezone(new \DateTimeZone('UTC'));
}
$value = $this->getIntlDateFormatter()->format((int)$dateTime->format('U'));
if (intl_get_error_code() != 0) {
throw new TransformationFailedException(intl_get_error_message());
}
return $value;
}