DateUtil::formatInterval now supports dates in the future
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 1 Nov 2012 17:15:32 +0000 (18:15 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 1 Nov 2012 17:16:14 +0000 (18:16 +0100)
wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php
wcfsetup/install/files/lib/util/DateUtil.class.php
wcfsetup/install/lang/de.xml

index c3ac5dc9b587d0a652eb10850a0115a12c6c1892..5aea312774f8d03561c30efd720b26bf099157ef 100644 (file)
@@ -33,8 +33,8 @@ class DateDiffModifierTemplatePlugin implements IModifierTemplatePlugin {
                        $fullInterval = $tagArgs[2];
                }
                
-               $startTime = DateUtil::getDateTimeByTimestamp(min($tagArgs[0], $tagArgs[1]));
-               $endTime = DateUtil::getDateTimeByTimestamp(max($tagArgs[0], $tagArgs[1]));
+               $startTime = DateUtil::getDateTimeByTimestamp($tagArgs[1]);
+               $endTime = DateUtil::getDateTimeByTimestamp($tagArgs[0]);
                
                return DateUtil::formatInterval($endTime->diff($startTime), $fullInterval);
        }
index 81e023915c8c5d1178b7106f1cd35af9a398920e..207ac301f1fa3f991e03139d7589f194c0362f6a 100644 (file)
@@ -174,9 +174,17 @@ final class DateUtil {
                $weeks = floor($days / 7);
                $hours = $interval->format('%h');
                $minutes = $interval->format('%i');
+               switch ($interval->format('%R')) {
+                       case '+':
+                               $direction = 'past';
+                       break;
+                       case '-':
+                               $direction = 'future';
+                       break;
+               }
                
                if ($fullInterval) {
-                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.full', array(
+                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.full.'.$direction, array(
                                'days' => $days - 7 * $weeks,
                                'firstElement' => $years ? 'years' : ($months ? 'months' : ($weeks ? 'weeks' : ($days ? 'days' : ($hours ? 'hours' : 'minutes')))),
                                'hours' => $hours,
@@ -189,36 +197,36 @@ final class DateUtil {
                }
                
                if ($years) {
-                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.years', array(
+                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.years.'.$direction, array(
                                'years' => $years
                        ));
                }
                
                if ($months) {
-                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.months', array(
+                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.months.'.$direction, array(
                                'months' => $months
                        ));
                }
                
                if ($weeks) {
-                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.weeks', array(
+                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.weeks.'.$direction, array(
                                'weeks' => $weeks
                        ));
                }
                
                if ($days) {
-                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.days', array(
+                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.days.'.$direction, array(
                                'days' => $days
                        ));
                }
                
                if ($hours) {
-                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.hours', array(
+                       return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.hours.'.$direction, array(
                                'hours' => $hours
                        ));
                }
                
-               return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.minutes', array(
+               return WCF::getLanguage()->getDynamicVariable('wcf.date.interval.minutes.'.$direction, array(
                        'minutes' => $minutes
                ));
        }
index bf261a909abf922b04fc38680c3f44408e772f61..da108bd2eba282d9e3ac80da60fa4e3b2ad871cd 100644 (file)
                <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>
+               <item name="wcf.date.interval.days.past"><![CDATA[Vor {if $days > 1}{#$days} Tagen{else}einem Tag{/if}]]></item>
+               <item name="wcf.date.interval.full.past"><![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.past"><![CDATA[Vor {if $hours > 1}{#$hours} Stunde{else}einer Stunde{/if}]]></item>
+               <item name="wcf.date.interval.minutes.past"><![CDATA[Vor {if $minutes > 1}{#$minutes} Minuten{else}einer Minute{/if}]]></item>
+               <item name="wcf.date.interval.months.past"><![CDATA[Vor {if $months > 1}{#$months} Monaten{else}einem Monat{/if}]]></item>
+               <item name="wcf.date.interval.weeks.past"><![CDATA[Vor {if $weeks > 1}{#$weeks} Wochen{else}einer Woche{/if}]]></item>
+               <item name="wcf.date.interval.years.past"><![CDATA[Vor {if $years > 1}{#$years} Jahren{else}einem Jahr{/if}]]></item>
+               
+               <item name="wcf.date.interval.days.future"><![CDATA[In {if $days > 1}{#$days} Tagen{else}einem Tag{/if}]]></item>
+               <item name="wcf.date.interval.full.future"><![CDATA[In {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.future"><![CDATA[In {if $hours > 1}{#$hours} Stunde{else}einer Stunde{/if}]]></item>
+               <item name="wcf.date.interval.minutes.future"><![CDATA[In {if $minutes > 1}{#$minutes} Minuten{else}einer Minute{/if}]]></item>
+               <item name="wcf.date.interval.months.future"><![CDATA[In {if $months > 1}{#$months} Monaten{else}einem Monat{/if}]]></item>
+               <item name="wcf.date.interval.weeks.future"><![CDATA[In {if $weeks > 1}{#$weeks} Wochen{else}einer Woche{/if}]]></item>
+               <item name="wcf.date.interval.years.future"><![CDATA[In {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>