From 506966c4f030bee5067d2c5eeec1edbfa0cc8e92 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 1 Nov 2012 18:15:32 +0100 Subject: [PATCH] DateUtil::formatInterval now supports dates in the future --- .../DateDiffModifierTemplatePlugin.class.php | 4 ++-- .../install/files/lib/util/DateUtil.class.php | 22 +++++++++++++------ wcfsetup/install/lang/de.xml | 22 +++++++++++++------ 3 files changed, 32 insertions(+), 16 deletions(-) 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 c3ac5dc9b5..5aea312774 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/DateDiffModifierTemplatePlugin.class.php @@ -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); } diff --git a/wcfsetup/install/files/lib/util/DateUtil.class.php b/wcfsetup/install/files/lib/util/DateUtil.class.php index 81e023915c..207ac301f1 100644 --- a/wcfsetup/install/files/lib/util/DateUtil.class.php +++ b/wcfsetup/install/files/lib/util/DateUtil.class.php @@ -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 )); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index bf261a909a..da108bd2eb 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -463,13 +463,21 @@ - 1}{#$days} Tagen{else}einem Tag{/if}]]> - 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}]]> - 1}{#$hours} Stunde{else}einer Stunde{/if}]]> - 1}{#$minutes} Minuten{else}einer Minute{/if}]]> - 1}{#$months} Monaten{else}einem Monat{/if}]]> - 1}{#$weeks} Wochen{else}einer Woche{/if}]]> - 1}{#$years} Jahren{else}einem Jahr{/if}]]> + 1}{#$days} Tagen{else}einem Tag{/if}]]> + 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}]]> + 1}{#$hours} Stunde{else}einer Stunde{/if}]]> + 1}{#$minutes} Minuten{else}einer Minute{/if}]]> + 1}{#$months} Monaten{else}einem Monat{/if}]]> + 1}{#$weeks} Wochen{else}einer Woche{/if}]]> + 1}{#$years} Jahren{else}einem Jahr{/if}]]> + + 1}{#$days} Tagen{else}einem Tag{/if}]]> + 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}]]> + 1}{#$hours} Stunde{else}einer Stunde{/if}]]> + 1}{#$minutes} Minuten{else}einer Minute{/if}]]> + 1}{#$months} Monaten{else}einem Monat{/if}]]> + 1}{#$weeks} Wochen{else}einer Woche{/if}]]> + 1}{#$years} Jahren{else}einem Jahr{/if}]]> 1) ? $minutes + ' Minuten' : 'einer Minute' )]]> -- 2.20.1