TYPO3 CMS  TYPO3_8-7
DateViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
85 {
87 
93  protected $escapeChildren = false;
94 
98  public function initializeArguments()
99  {
100  parent::initializeArguments();
101  $this->registerArgument('date', 'mixed', 'Either an object implementing DateTimeInterface or a string that is accepted by DateTime constructor');
102  $this->registerArgument('format', 'string', 'Format String which is taken to format the Date/Time', false, '');
103  $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.');
104  }
105 
114  public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
115  {
116  $format = $arguments['format'];
117  $base = $arguments['base'] === null ? time() : $arguments['base'];
118  if (is_string($base)) {
119  $base = trim($base);
120  }
121 
122  if ($format === '') {
123  $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d';
124  }
125 
126  $date = $renderChildrenClosure();
127  if ($date === null) {
128  return '';
129  }
130 
131  if (is_string($date)) {
132  $date = trim($date);
133  }
134 
135  if ($date === '') {
136  $date = 'now';
137  }
138 
139  if (!$date instanceof \DateTimeInterface) {
140  try {
141  $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base);
142  $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base);
143  $date = new \DateTime('@' . $dateTimestamp);
144  $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
145  } catch (\Exception $exception) {
146  throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579);
147  }
148  }
149 
150  if (strpos($format, '%') !== false) {
151  return strftime($format, $date->format('U'));
152  }
153  return $date->format($format);
154  }
155 }
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']