TYPO3  7.6
DateViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
19 
84 {
88  protected $escapingInterceptorEnabled = false;
89 
101  public function render($date = null, $format = '', $base = null)
102  {
103  return static::renderStatic(
104  array(
105  'date' => $date,
106  'format' => $format,
107  'base' => $base
108  ),
110  $this->renderingContext
111  );
112  }
113 
123  {
124  $date = $arguments['date'];
125  $format = $arguments['format'];
126  $base = $arguments['base'] === null ? time() : $arguments['base'];
127 
128  if ($format === '') {
129  $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d';
130  }
131 
132  if ($date === null) {
133  $date = $renderChildrenClosure();
134  if ($date === null) {
135  return '';
136  }
137  }
138 
139  if ($date === '') {
140  $date = 'now';
141  }
142 
143  if (!$date instanceof \DateTime) {
144  try {
145  $base = $base instanceof \DateTime ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base);
146  $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base);
147  $date = new \DateTime('@' . $dateTimestamp);
148  $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
149  } catch (\Exception $exception) {
150  throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579);
151  }
152  }
153 
154  if (strpos($format, '%') !== false) {
155  return strftime($format, $date->format('U'));
156  } else {
157  return $date->format($format);
158  }
159  }
160 }