* Usage:
* {$endTimestamp|dateDiff}
* {$endTimestamp|dateDiff:$startTimestamp:$fullInterval}
- * {$endTimestamp|dateDiff:$startTimestamp:$fullInterval:$formatType}
*
* @author Matthias Schmidt, Marcel Werk
* @copyright 2001-2017 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\System\Template\Plugin
+ * @deprecated since 3.1, use `DateIntervalFunctionTemplatePlugin`
*/
class DateDiffModifierTemplatePlugin implements IModifierTemplatePlugin {
/**
$fullInterval = $tagArgs[2];
}
- $formatType = DateUtil::FORMAT_DEFAULT;
- if (isset($tagArgs[3])) {
- if (!defined(DateUtil::class .'::'. strtoupper($tagArgs[3]))) {
- throw new \InvalidArgumentException('Invalid $formatType value');
- }
-
- $formatType = constant(DateUtil::class .'::'. strtoupper($tagArgs[3]));
- }
-
$startTime = DateUtil::getDateTimeByTimestamp($tagArgs[1]);
$endTime = DateUtil::getDateTimeByTimestamp($tagArgs[0]);
- return DateUtil::formatInterval($endTime->diff($startTime), $fullInterval, $formatType);
+ return DateUtil::formatInterval($endTime->diff($startTime), $fullInterval);
}
}
--- /dev/null
+<?php
+namespace wcf\system\template\plugin;
+use wcf\system\template\TemplateEngine;
+use wcf\util\DateUtil;
+
+/**
+ * Template modifier plugin which calculates the difference between two unix timestamps
+ * and returns it as a textual date interval.
+ * Compared to `DateDiffModifierTemplatePlugin`, this plugin allows a cleaner syntax
+ * and offers more features.
+ *
+ * Usage:
+ * {dateInterval start=$startTimestamp end=$endTimestamp full=true format='sentence'}
+ *
+ * Parameters:
+ * - `start` refers to the start of the time interval, defaults to the current time
+ * - `end` refers to the end of the time interval, default to the current time
+ * (though either `start` or `end` has to be set)
+ * - `full` determines if the full difference down to minutes (`true`) will be
+ * shown or just the longest time interval type, defaults to `false`
+ * - `format` determines how the output is formatted, see `DateUtil::FORMAT_*`
+ * constants, defaults to `default`
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2017 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Template\Plugin
+ * @since 3.1
+ */
+class DateIntervalFunctionTemplatePlugin implements IFunctionTemplatePlugin {
+ /**
+ * @inheritDoc
+ */
+ public function execute($tagArgs, TemplateEngine $tplObj) {
+ // read start and end time, each defaulting to current time
+ $start = $end = TIME_NOW;
+
+ if (!isset($tagArgs['start']) && !isset($tagArgs['end'])) {
+ throw new \InvalidArgumentException("Neither a 'start' nor an 'end' argument has been provided.");
+ }
+
+ if (isset($tagArgs['start'])) {
+ $start = intval($tagArgs['start']);
+ }
+ if (isset($tagArgs['end'])) {
+ $end = intval($tagArgs['end']);
+ }
+
+ $startTime = DateUtil::getDateTimeByTimestamp($start);
+ $endTime = DateUtil::getDateTimeByTimestamp($end);
+
+ // read `full` flag for output precision
+ $fullInterval = false;
+ if (!empty($tagArgs['full'])) {
+ $fullInterval = true;
+ }
+
+ // read output format
+ $formatType = DateUtil::FORMAT_DEFAULT;
+ if (isset($tagArgs['format'])) {
+ $constant = DateUtil::class .'::FORMAT_'. strtoupper($tagArgs['format']);
+ if (!defined($constant)) {
+ throw new \InvalidArgumentException("Invalid format '{$tagArgs['format']}' provided.");
+ }
+
+ $formatType = constant($constant);
+ }
+
+ return DateUtil::formatInterval($endTime->diff($startTime), $fullInterval, $formatType);
+ }
+}
<item name="wcf.paidSubscription.confirmTOS"><![CDATA[Hiermit bestätige ich mein Einverständnis mit den <a href="{PAID_SUBSCRIPTION_TOS_URL}">Nutzungsbedingungen</a>]]></item>
<item name="wcf.paidSubscription.button.moreInformation"><![CDATA[Mehr Informationen]]></item>
<item name="wcf.paidSubscription.expiringSubscription.notification.title"><![CDATA[Ablaufende Mitgliedschaft]]></item>
- <item name="wcf.paidSubscription.expiringSubscription.notification.message"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} Mitgliedschaft „{$userNotificationObject->getTitle()}“ läuft {$userNotificationObject->endDate|dateDiff:$notification->time:false:"format_sentence"} (am {$userNotificationObject->endDate|date:'d. F'}) ab.]]></item>
+ <item name="wcf.paidSubscription.expiringSubscription.notification.message"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} Mitgliedschaft „{$userNotificationObject->getTitle()}“ läuft {dateInterval start=$notification->time end=$userNotificationObject->endDate format='sentence'} (am {$userNotificationObject->endDate|date:'d. F'}) ab.]]></item>
</category>
<category name="wcf.payment">
<item name="wcf.paidSubscription.confirmTOS"><![CDATA[I agree to the <a href="{PAID_SUBSCRIPTION_TOS_URL}">Terms of Service</a>]]></item>
<item name="wcf.paidSubscription.button.moreInformation"><![CDATA[More Details]]></item>
<item name="wcf.paidSubscription.expiringSubscription.notification.title"><![CDATA[Expiring Subscription]]></item>
- <item name="wcf.paidSubscription.expiringSubscription.notification.message"><![CDATA[Your subscription “{$userNotificationObject->getTitle()}” will expire {$userNotificationObject->endDate|dateDiff:$notification->time:false:"format_sentence"} (on {$userNotificationObject->endDate|date:'F jS'}).]]></item>
+ <item name="wcf.paidSubscription.expiringSubscription.notification.message"><![CDATA[Your subscription “{$userNotificationObject->getTitle()}” will expire {dateInterval start=$notification->time end=$userNotificationObject->endDate format='sentence'} (on {$userNotificationObject->endDate|date:'F jS'}).]]></item>
</category>
<category name="wcf.payment">