From: Matthias Schmidt Date: Sat, 10 Jun 2017 13:35:01 +0000 (+0200) Subject: Add DateIntervalFunctionTemplatePlugin X-Git-Tag: 3.1.0_Alpha_1~383 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7ec10692f585d5e0bd8c9cadbcc40ef6705e738e;p=GitHub%2FWoltLab%2FWCF.git Add DateIntervalFunctionTemplatePlugin Closes #2303 --- diff --git a/wcfsetup/install/files/acp/templates/sitemapList.tpl b/wcfsetup/install/files/acp/templates/sitemapList.tpl index 98d64712dc..e58164cdb0 100755 --- a/wcfsetup/install/files/acp/templates/sitemapList.tpl +++ b/wcfsetup/install/files/acp/templates/sitemapList.tpl @@ -38,8 +38,8 @@ objectType}{/link}">{lang}wcf.acp.sitemap.objectType.{$object->objectType}{/lang} {$object->priority} {lang}wcf.acp.sitemap.changeFreq.{$object->changeFreq}{/lang} - {@TIME_NOW + $object->rebuildTime|dateDiff:TIME_NOW:true:"format_plain"} - + {dateInterval end=TIME_NOW+$object->rebuildTime full=true format='plain'} + {event name='columns'} {/foreach} diff --git a/wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php index b3ecd4bc4c..4e472669d4 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php @@ -11,12 +11,12 @@ use wcf\util\DateUtil; * 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 * @package WoltLabSuite\Core\System\Template\Plugin + * @deprecated since 3.1, use `DateIntervalFunctionTemplatePlugin` */ class DateDiffModifierTemplatePlugin implements IModifierTemplatePlugin { /** @@ -32,18 +32,9 @@ 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); } } diff --git a/wcfsetup/install/files/lib/system/template/plugin/DateIntervalFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/DateIntervalFunctionTemplatePlugin.class.php new file mode 100644 index 0000000000..ca8c6f32ce --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/DateIntervalFunctionTemplatePlugin.class.php @@ -0,0 +1,71 @@ + + * @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); + } +} diff --git a/wcfsetup/install/files/lib/util/DateUtil.class.php b/wcfsetup/install/files/lib/util/DateUtil.class.php index d7b0b1e1a4..af4b2cd797 100644 --- a/wcfsetup/install/files/lib/util/DateUtil.class.php +++ b/wcfsetup/install/files/lib/util/DateUtil.class.php @@ -228,7 +228,7 @@ final class DateUtil { case self::FORMAT_SENTENCE: $languageItemSuffix = $direction . '.inSentence'; break; - + case self::FORMAT_PLAIN: $languageItemSuffix = 'plain'; break; diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 7657abe5e0..136b02321a 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3032,7 +3032,7 @@ Fehler sind beispielsweise: Nutzungsbedingungen]]> - getTitle()}“ läuft {$userNotificationObject->endDate|dateDiff:$notification->time:false:"format_sentence"} (am {$userNotificationObject->endDate|date:'d. F'}) ab.]]> + getTitle()}“ läuft {dateInterval start=$notification->time end=$userNotificationObject->endDate format='sentence'} (am {$userNotificationObject->endDate|date:'d. F'}) ab.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 70a8683d88..64e4efce14 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3025,7 +3025,7 @@ Errors are: Terms of Service]]> - getTitle()}” will expire {$userNotificationObject->endDate|dateDiff:$notification->time:false:"format_sentence"} (on {$userNotificationObject->endDate|date:'F jS'}).]]> + getTitle()}” will expire {dateInterval start=$notification->time end=$userNotificationObject->endDate format='sentence'} (on {$userNotificationObject->endDate|date:'F jS'}).]]>