--- /dev/null
+<?php
+namespace wcf\system\template\plugin;
+use wcf\system\template\TemplateEngine;
+use wcf\util\DateUtil;
+
+/**
+ * The 'dateDiff' modifier calculates the difference between two unix timestamps
+ * and returns it as a textual date interval. The second parameter $fullInterval
+ * indicates if the full difference is returned or just a rounded difference.
+ *
+ * Usage:
+ * {$timestamp|dateDiff}
+ * {"123456789"|dateDiff:$timestamp:$fullInverval}
+ *
+ * @author Matthias Schmidt, Marcel Werk
+ * @copyright 2001-2012 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.template.plugin
+ * @category Community Framework
+ */
+class DateDiffModifierTemplatePlugin implements IModifierTemplatePlugin {
+ /**
+ * @see wcf\system\template\IModifierTemplatePlugin::execute()
+ */
+ public function execute($tagArgs, TemplateEngine $tplObj) {
+ if (!isset($tagArgs[1])) {
+ $tagArgs[1] = TIME_NOW;
+ }
+
+ $fullInterval = false;
+ if (isset($tagArgs[2])) {
+ $fullInterval = $tagArgs[2];
+ }
+
+ $startTime = DateUtil::getDateTimeByTimestamp(min($tagArgs[0], $tagArgs[1]));
+ $endTime = DateUtil::getDateTimeByTimestamp(max($tagArgs[0], $tagArgs[1]));
+
+ return DateUtil::formatInterval($endTime->diff($startTime), $fullInterval);
+ }
+}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\TemplateEngine;
-use wcf\util\DateUtil;
-
-/**
- * The 'datediff' modifier calculates the difference between two unix timestamps.
- *
- * Usage:
- * {$timestamp|datediff}
- * {"123456789"|datediff:$timestamp}
- *
- * @author Marcel Werk
- * @copyright 2001-2011 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class DatediffModifierTemplatePlugin implements IModifierTemplatePlugin {
- /**
- * @see wcf\system\template\IModifierTemplatePlugin::execute()
- */
- public function execute($tagArgs, TemplateEngine $tplObj) {
- // get timestamps
- if (!isset($tagArgs[1])) $tagArgs[1] = TIME_NOW;
- $start = min($tagArgs[0], $tagArgs[1]);
- $end = max($tagArgs[0], $tagArgs[1]);
-
- // TODO: method doesn't exists anymore
- // return DateUtil::diff($start, $end, 'string');
- return '';
- }
-}
* @param string $format
* @param wcf\data\language\Language $language
* @param wcf\data\user\User $user
+ * @return string
*/
public static function format(\DateTime $time = null, $format = null, Language $language = null, User $user = null) {
// get default values
return $output;
}
+ /**
+ * Returns a formatted date interval. If $fullInterval is set true, the
+ * complete interval is returned, otherwise a rounded interval is used.
+ *
+ * @param \DateInterval $interval
+ * @param boolean $fullInterval
+ * @return string
+ */
+ public static function formatInterval(\DateInterval $interval, $fullInterval = false) {
+ $years = $interval->format('%y');
+ $months = $interval->format('%m');
+ $days = $interval->format('%d');
+ $weeks = floor($days / 7);
+ $hours = $interval->format('%h');
+ $minutes = $interval->format('%i');
+
+ if ($fullInterval) {
+ return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.full', array(
+ 'days' => $days - 7 * $weeks,
+ 'firstElement' => $years ? 'years' : ($months ? 'months' : ($weeks ? 'weeks' : ($days ? 'days' : ($hours ? 'hours' : 'minutes')))),
+ 'hours' => $hours,
+ 'lastElement' => !$minutes ? (!$hours ? (!$days ? (!$weeks ? (!$months ? 'years' : 'months') : 'weeks') : 'days') : 'hours') : 'minutes',
+ 'minutes' => $minutes,
+ 'months' => $months,
+ 'weeks' => $weeks,
+ 'years' => $years
+ ));
+ }
+
+ if ($years) {
+ return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.years', array(
+ 'years' => $years
+ ));
+ }
+
+ if ($months) {
+ return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.months', array(
+ 'months' => $months
+ ));
+ }
+
+ if ($days) {
+ if ($days > 7) {
+ return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.weeks', array(
+ 'weeks' => $weeks
+ ));
+ }
+
+ return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.days', array(
+ 'days' => $days
+ ));
+ }
+
+ if ($hours) {
+ return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.hours', array(
+ 'hours' => $hours
+ ));
+ }
+
+ return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.minutes', array(
+ 'minutes' => $minutes
+ ));
+ }
+
/**
* Returns a localized date output.
*
<item name="wcf.date.timeFormat"><![CDATA[H:i]]></item>
<item name="wcf.date.dateTimeFormat"><![CDATA[%date%, %time%]]></item>
+ <item name="wcf.date.interval.days"><![CDATA[Vor {if $days > 1}{#$days} Tagen{else}einem Tag{/if}]]></item>
+ <item name="wcf.date.interval.full"><![CDATA[Vor {if $years}{if $years > 1}{#$years} Jahren{else}einem Jahr{/if}{/if}{if $months}{if $firstElement != 'months'}{if $lastElement == 'months'} und {else}, {/if}{/if}{if $months > 1}{#$months} Monaten{else}einem Monat{/if}{/if}{if $weeks}{if $firstElement != 'weeks'}{if $lastElement == 'weeks'} und {else}, {/if}{/if}{if $weeks > 1}{#$weeks} Wochen{else}einer Woche{/if}{/if}{if $days}{if $firstElement != 'days'}{if $lastElement == 'days'} und {else}, {/if}{/if}{if $days > 1}{#$days} Tagen{else}einem Tag{/if}{/if}{if $hours}{if $firstElement != 'hours'}{if $lastElement == 'hours'} und {else}, {/if}{/if}{if $hours > 1}{#$hours} Stunden{else}einer Stunde{/if}{/if}{if $minutes}{if $firstElement != 'minutes' && $lastElement == 'minutes'} und {/if}{if $minutes > 1}{#$minutes} Minuten{else}einer Minute{/if}{/if}]]></item>
+ <item name="wcf.date.interval.hours"><![CDATA[Vor {if $hours > 1}{#$hours} Stunde{else}einer Stunde{/if}]]></item>
+ <item name="wcf.date.interval.minutes"><![CDATA[Vor {if $minutes > 1}{#$minutes} Minuten{else}einer Minute{/if}]]></item>
+ <item name="wcf.date.interval.months"><![CDATA[Vor {if $months > 1}{#$months} Monaten{else}einem Monat{/if}]]></item>
+ <item name="wcf.date.interval.weeks"><![CDATA[Vor {if $weeks > 1}{#$weeks} Wochen{else}einer Woche{/if}]]></item>
+ <item name="wcf.date.interval.years"><![CDATA[Vor {if $years > 1}{#$years} Jahren{else}einem Jahr{/if}]]></item>
+
<!-- variables for dynamic javascript datetime -->
<item name="wcf.date.relative.minutes"><![CDATA['Vor ' + (($minutes > 1) ? $minutes + ' Minuten' : 'einer Minute' )]]></item>
<item name="wcf.date.relative.hours"><![CDATA['Vor ' + (($hours > 1) ? $hours + ' Stunden' : 'einer Stunde' )]]></item>
<item name="wcf.date.timeFormat"><![CDATA[g:ia]]></item>
<item name="wcf.date.dateTimeFormat"><![CDATA[%date%, %time%]]></item>
+ <item name="wcf.date.interval.days"><![CDATA[{if $days > 1}{#$days} days{else}A day{/if} ago]]></item>
+ <item name="wcf.date.interval.full"><![CDATA[{if $years}{if $years > 1}{#$years} years{else}A year{/if}{/if}{if $months}{if $firstElement != 'months'}{if $firstElement != 'months'}{if $lastElement == 'months'} and {else}, {/if}{/if}{#$months} months{else}{if $firstElement == 'months'}A{else}a{/if} month{/if}{/if}{if $weeks}{if $firstElement != 'weeks'}{if $lastElement == 'weeks'} and {else}, {/if}{/if}{if $weeks > 1}{#$weeks} weeks{else}{if $firstElement == 'weeks'}A{else}a{/if} week{/if}{/if}{if $days}{if $firstElement != 'days'}{if $lastElement == 'days'} and {else}, {/if}{/if}{if $days > 1}{#$days} days{else}{if $firstElement == 'days'}A{else}a{/if} day{/if}{/if}{if $hours}{if $firstElement != 'hours'}{if $lastElement == 'hours'} and {else}, {/if}{/if}{if $hours > 1}{#$hours} hours{else}{if $firstElement == 'hours'}An{else}an{/if} hour{/if}{/if}{if $minutes}{if $firstElement != 'minutes' && $lastElement == 'minutes'} and {/if}{if $minutes > 1}{#$minutes} minutes{else}{if $firstElement == 'minutes'}A{else}a{/if} minute{/if}{/if} ago]]></item>
+ <item name="wcf.date.interval.hours"><![CDATA[{if $hours > 1}{#$hours} hours{else}An hour{/if} ago]]></item>
+ <item name="wcf.date.interval.minutes"><![CDATA[{if $minutes > 1}{#$minutes} minutes{else}A minute{/if} ago]]></item>
+ <item name="wcf.date.interval.months"><![CDATA[{if $months > 1}{#$months} months{else}A Month{/if} ago]]></item>
+ <item name="wcf.date.interval.weeks"><![CDATA[{if $weeks > 1}{#$weeks} weeks{else}A week{/if} ago]]></item>
+ <item name="wcf.date.interval.years"><![CDATA[{if $years > 1}{#$years} years{else}A year{/if} ago]]></item>
+
<!-- variables for dynamic javascript datetime -->
<item name="wcf.date.relative.minutes"><![CDATA[(($minutes > 1) ? $minutes + ' minutes' : 'A minute') + ' ago']]></item>
<item name="wcf.date.relative.hours"><![CDATA[(($hours > 1) ? $hours + ' hours' : 'An hour' ) + ' ago']]></item>