TYPO3 CMS  TYPO3_7-6
DateViewHelper.php
Go to the documentation of this file.
1 <?php
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  [
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  if (is_string($base)) {
128  $base = trim($base);
129  }
130 
131  if ($format === '') {
132  $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d';
133  }
134 
135  if ($date === null) {
136  $date = $renderChildrenClosure();
137  if ($date === null) {
138  return '';
139  }
140  }
141 
142  if (is_string($date)) {
143  $date = trim($date);
144  }
145 
146  if ($date === '') {
147  $date = 'now';
148  }
149 
150  if (!$date instanceof \DateTimeInterface) {
151  try {
152  $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base);
153  $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base);
154  $date = new \DateTime('@' . $dateTimestamp);
155  $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
156  } catch (\Exception $exception) {
157  throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579);
158  }
159  }
160 
161  if (strpos($format, '%') !== false) {
162  return strftime($format, $date->format('U'));
163  } else {
164  return $date->format($format);
165  }
166  }
167 }
static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
render($date=null, $format='', $base=null)