Adds missing class
authorMatthias Schmidt <gravatronics@live.com>
Tue, 9 Oct 2012 17:22:59 +0000 (19:22 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 9 Oct 2012 17:22:59 +0000 (19:22 +0200)
wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php
new file mode 100644 (file)
index 0000000..c3ac5dc
--- /dev/null
@@ -0,0 +1,41 @@
+<?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);
+       }
+}