public function render($date = null, $format = 'Y-m-d', $localeFormatType = null, $localeFormatLength = null, $cldrFormat = null)
{
if ($date === null) {
$date = $this->renderChildren();
if ($date === null) {
return '';
}
}
if (!$date instanceof \DateTimeInterface) {
try {
$date = new \DateTime($date);
} catch (\Exception $exception) {
throw new ViewHelperException('"' . $date . '" could not be parsed by \\DateTime constructor.', 1241722579, $exception);
}
}
$useLocale = $this->getLocale();
if ($useLocale !== null) {
try {
if ($cldrFormat !== null) {
$output = $this->datetimeFormatter->formatDateTimeWithCustomPattern($date, $cldrFormat, $useLocale);
} else {
$output = $this->datetimeFormatter->format($date, $useLocale, array($localeFormatType, $localeFormatLength));
}
} catch (I18nException $exception) {
throw new ViewHelperException(sprintf('An error occurred while trying to format the given date/time: "%s"', $exception->getMessage()), 1342610987, $exception);
}
} else {
$output = $date->format($format);
}
return $output;
}