<?php

namespace wcf\system\template\plugin;

use wcf\system\template\TemplateEngine;
use wcf\system\WCF;
use wcf\util\DateUtil;

/**
 * Template modifier plugin which formats a unix timestamp.
 * Default date format contains year, month, day, hour and minute.
 *
 * Usage:
 *  {$timestamp|time}
 *  {"132845333"|time}
 *
 * @author Alexander Ebert, Marcel Werk
 * @copyright 2001-2022 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package WoltLabSuite\Core\System\Template\Plugin
 */
class TimeModifierTemplatePlugin implements IModifierTemplatePlugin
{
    /**
     * @inheritDoc
     */
    public function execute($tagArgs, TemplateEngine $tplObj)
    {
        $timestamp = \intval($tagArgs[0]);
        $dateTimeObject = DateUtil::getDateTimeByTimestamp($timestamp);
        $isFutureDate = ($timestamp > TIME_NOW);
        $dateAndTime = \IntlDateFormatter::create(
            WCF::getLanguage()->getLocale(),
            \IntlDateFormatter::LONG,
            \IntlDateFormatter::SHORT,
            WCF::getUser()->getTimeZone()
        )->format($dateTimeObject);

        return \sprintf(
            '<woltlab-core-date-time date="%s"%s>%s</woltlab-core-date-time>',
            DateUtil::format($dateTimeObject, 'c'),
            $isFutureDate ? ' static' : '',
            $dateAndTime
        );
    }
}

<?php

namespace wcf\system\template\plugin;

use wcf\system\template\TemplateEngine;
use wcf\system\WCF;

/**
 * Template modifier plugin which formats a unix timestamp.
 * Default date format contains year, month, day, hour and minute.
 *
 * Usage:
 *  {$timestamp|time}
 *  {"132845333"|time}
 *
 * @author Alexander Ebert, Marcel Werk
 * @copyright 2001-2022 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package WoltLabSuite\Core\System\Template\Plugin
 */
class TimeModifierTemplatePlugin implements IModifierTemplatePlugin
{
    /**
     * @inheritDoc
     */
    public function execute($tagArgs, TemplateEngine $tplObj)
    {
        $timestamp = \intval($tagArgs[0]);
        $dateTime = new \DateTimeImmutable('@' . $timestamp);

        $isFutureDate = $dateTime->getTimestamp() > TIME_NOW;

        $dateAndTime = \IntlDateFormatter::create(
            WCF::getLanguage()->getLocale(),
            \IntlDateFormatter::LONG,
            \IntlDateFormatter::SHORT,
            WCF::getUser()->getTimeZone()
        )->format($dateTime);

        return \sprintf(
            '<woltlab-core-date-time date="%s"%s>%s</woltlab-core-date-time>',
            $dateTime->format('c'),
            $isFutureDate ? ' static' : '',
            $dateAndTime
        );
    }
}

Clean up implementation of TimeModifierTemplatePlugin
Clean up implementation of TimeModifierTemplatePlugin

No need to use the DateUtil here. `getDateTimeByTimestamp()` is trivial,
localization already happens via `IntlDateFormatter` and the `c` format is
meant for technical consumption, thus no need to run this via `DateUtil`’s
localization and TZ logic.
