20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
103 use CompileWithContentArgumentAndRenderStatic;
117 $this->registerArgument(
'date',
'mixed',
'Either an object implementing DateTimeInterface or a string that is accepted by DateTime constructor');
118 $this->registerArgument(
'format',
'string',
'Format String which is taken to format the Date/Time',
false,
'');
119 $this->registerArgument(
'base',
'mixed',
'A base time (an object implementing DateTimeInterface or a string) used if $date is a relative date specification. Defaults to current time.');
130 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
132 $format = $arguments[
'format'];
133 $base = $arguments[
'base'] ?? GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect(
'date',
'timestamp');
134 if (is_string($base)) {
138 if ($format ===
'') {
139 $format =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'ddmmyy'] ?:
'Y-m-d';
142 $date = $renderChildrenClosure();
143 if ($date ===
null) {
147 if (is_string($date)) {
155 if (!$date instanceof \DateTimeInterface) {
159 $date = new \DateTime(
'@' . $dateTimestamp);
160 $date->setTimezone(
new \DateTimeZone(date_default_timezone_get()));
161 }
catch (\Exception $exception) {
162 throw new Exception(
'"' . $date .
'" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579);
166 if (strpos($format,
'%') !==
false) {
167 return strftime($format, $date->format(
'U'));
169 return $date->format($format);