Project

General

Profile

Feature #92760 ยป Bugfixing_in_format_dateViewhelper1.patch

Dieter Porth, 2020-11-03 14:33

View differences:

Source/web/typo3conf/ext/timer/Classes/ViewHelpers/Format/DateViewHelper.php (date 1604410248331)
{
$this->registerArgument('date', 'mixed', 'Either an object implementing DateTimeInterface or a string that is accepted by DateTime constructor');
$this->registerArgument('format', 'string', 'Format String which is taken to format the Date/Time', false, '');
$this->registerArgument('zone', 'string', 'Timezone for the date, if it is different from the Timezone of TYPO3', false, '');
$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.');
}
......
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$zone = date_default_timezone_get();
if (isset($arguments['zone']) && (!empty($arguments['zone']))) {
$help = $arguments['zone'];
$zoneList = timezone_identifiers_list(); # list of (all) valid timezones
$zone = (in_array($help, $zoneList)?
$help:
date_default_timezone_get()
);
}
$format = $arguments['format'];
$base = $arguments['base'] ?? GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('date', 'timestamp');
if (is_string($base)) {
......
$base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base);
$dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base);
$date = new \DateTime('@' . $dateTimestamp);
$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
} catch (\Exception $exception) {
throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579);
}
}
$date->setTimezone(new \DateTimeZone($zone));
if (strpos($format, '%') !== false) {
return strftime($format, $date->format('U'));
    (1-1/1)