* Usage:
* {$endTimestamp|dateDiff}
* {$endTimestamp|dateDiff:$startTimestamp:$fullInterval}
- * {$endTimestamp|dateDiff:$startTimestamp:$fullInterval:$inSentence}
+ * {$endTimestamp|dateDiff:$startTimestamp:$fullInterval:$formatType}
*
* @author Matthias Schmidt, Marcel Werk
* @copyright 2001-2017 WoltLab GmbH
$fullInterval = $tagArgs[2];
}
- $inSentence = false;
+ $formatType = DateUtil::FORMAT_DEFAULT;
if (isset($tagArgs[3])) {
- $inSentence = $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, $inSentence);
+ return DateUtil::formatInterval($endTime->diff($startTime), $fullInterval, $formatType);
}
}
*/
const TIME_FORMAT = 'wcf.date.timeFormat';
+ /**
+ * format the interval to be used as a standalone phrase
+ * @var integer
+ */
+ const FORMAT_DEFAULT = 1;
+
+ /**
+ * format the interval to be used as a phrase in a sentence
+ * @var integer
+ */
+ const FORMAT_SENTENCE = 2;
+
+ /**
+ * format the interval without direction
+ * @var integer
+ */
+ const FORMAT_PLAIN = 3;
+
/**
* list of available time zones
* @var string[]
*
* @param \DateInterval $interval interval to be formatted
* @param boolean $fullInterval if `true`, the complete interval is returned, otherwise a rounded interval is used
- * @param boolean $inSentence if `true`, the returned phrase is considered to be used in a sentence, otherwise as a standalone phrase
+ * @param integer $formatType format type for the interval, use the class constant FORMAT_DEFAULT, FORMAT_SENTENCE or FORMAT_PLAIN
* @return string
*/
- public static function formatInterval(\DateInterval $interval, $fullInterval = false, $inSentence = false) {
+ public static function formatInterval(\DateInterval $interval, $fullInterval = false, $formatType = self::FORMAT_DEFAULT) {
$years = $interval->format('%y');
$months = $interval->format('%m');
$days = $interval->format('%d');
break;
}
- $languageItemSuffix = $direction;
- if ($inSentence) {
- $languageItemSuffix .= '.inSentence';
+ switch ($formatType) {
+ case self::FORMAT_DEFAULT:
+ $languageItemSuffix = $direction;
+ break;
+
+ case self::FORMAT_SENTENCE:
+ $languageItemSuffix = $direction . '.inSentence';
+ break;
+
+ case self::FORMAT_PLAIN:
+ $languageItemSuffix = 'plain';
+ break;
+
+ default:
+ throw new \InvalidArgumentException('Invalid $formatType value');
}
if ($fullInterval) {
<item name="wcf.date.interval.weeks.future.inSentence"><![CDATA[in {if $weeks > 1}{#$weeks} Wochen{else}einer Woche{/if}]]></item>
<item name="wcf.date.interval.years.future.inSentence"><![CDATA[in {if $years > 1}{#$years} Jahren{else}einem Jahr{/if}]]></item>
+ <item name="wcf.date.interval.days.plain"><![CDATA[{if $days > 1}{#$days} Tage{else}ein Tag{/if}]]></item>
+ <item name="wcf.date.interval.full.plain"><![CDATA[{if $years}{if $years > 1}{#$years} Jahre{else}ein Jahr{/if}{/if}{if $months}{if $firstElement != 'months'}{if $lastElement == 'months'} und {else}, {/if}{/if}{if $months > 1}{#$months} Monate{else}ein Monat{/if}{/if}{if $weeks}{if $firstElement != 'weeks'}{if $lastElement == 'weeks'} und {else}, {/if}{/if}{if $weeks > 1}{#$weeks} Wochen{else}eine Woche{/if}{/if}{if $days}{if $firstElement != 'days'}{if $lastElement == 'days'} und {else}, {/if}{/if}{if $days > 1}{#$days} Tage{else}ein Tag{/if}{/if}{if $hours}{if $firstElement != 'hours'}{if $lastElement == 'hours'} und {else}, {/if}{/if}{if $hours > 1}{#$hours} Stunden{else}eine Stunde{/if}{/if}{if $minutes}{if $firstElement != 'minutes' && $lastElement == 'minutes'} und {/if}{if $minutes > 1}{#$minutes} Minuten{else}eine Minute{/if}{/if}]]></item>
+ <item name="wcf.date.interval.hours.plain"><![CDATA[{if $hours > 1}{#$hours} Stunden{else}eine Stunde{/if}]]></item>
+ <item name="wcf.date.interval.minutes.plain"><![CDATA[{if $minutes > 1}{#$minutes} Minuten{else}eine Minute{/if}]]></item>
+ <item name="wcf.date.interval.months.plain"><![CDATA[{if $months > 1}{#$months} Monate{else}ein Monat{/if}]]></item>
+ <item name="wcf.date.interval.weeks.plain"><![CDATA[{if $weeks > 1}{#$weeks} Wochen{else}eine Woche{/if}]]></item>
+ <item name="wcf.date.interval.years.plain"><![CDATA[{if $years > 1}{#$years} Jahre{else}ein Jahr{/if}]]></item>
+
<!-- variables for time periods -->
<item name="wcf.date.period.older"><![CDATA[Älter]]></item>
<item name="wcf.date.period.today"><![CDATA[Heute]]></item>
<item name="wcf.paidSubscription.confirmTOS"><![CDATA[Hiermit bestätige ich mein Einverständnis mit den <a href="{PAID_SUBSCRIPTION_TOS_URL}">Nutzungsbedingungen</a>]]></item>
<item name="wcf.paidSubscription.button.moreInformation"><![CDATA[Mehr Informationen]]></item>
<item name="wcf.paidSubscription.expiringSubscription.notification.title"><![CDATA[Ablaufende Mitgliedschaft]]></item>
- <item name="wcf.paidSubscription.expiringSubscription.notification.message"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} Mitgliedschaft „{$userNotificationObject->getTitle()}“ läuft {$userNotificationObject->endDate|dateDiff:$notification->time:false:true} (am {$userNotificationObject->endDate|date:'d. F'}) ab.]]></item>
+ <item name="wcf.paidSubscription.expiringSubscription.notification.message"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} Mitgliedschaft „{$userNotificationObject->getTitle()}“ läuft {$userNotificationObject->endDate|dateDiff:$notification->time:false:"format_sentence"} (am {$userNotificationObject->endDate|date:'d. F'}) ab.]]></item>
</category>
<category name="wcf.payment">
<item name="wcf.date.interval.weeks.future.inSentence"><![CDATA[in {if $weeks > 1}{#$weeks} weeks{else}a week{/if}]]></item>
<item name="wcf.date.interval.years.future.inSentence"><![CDATA[in {if $years > 1}{#$years} years{else}a year{/if}]]></item>
+ <item name="wcf.date.interval.days.plain"><![CDATA[{if $days > 1}{#$days} days{else}one day{/if}]]></item>
+ <item name="wcf.date.interval.full.plain"><![CDATA[{if $years}{if $years > 1}{#$years} years{else}one year{/if}{/if}{if $months}{if $firstElement != 'months'}{if $lastElement == 'months'} and {else}, {/if}{/if}{if $months > 1}{#$months} months{else}one month{/if}{/if}{if $weeks}{if $firstElement != 'weeks'}{if $lastElement == 'weeks'} and {else}, {/if}{/if}{if $weeks > 1}{#$weeks} weeks{else}one week{/if}{/if}{if $days}{if $firstElement != 'days'}{if $lastElement == 'days'} and {else}, {/if}{/if}{if $days > 1}{#$days} days{else}one day{/if}{/if}{if $hours}{if $firstElement != 'hours'}{if $lastElement == 'hours'} and {else}, {/if}{/if}{if $hours > 1}{#$hours} hours{else}one hour{/if}{/if}{if $minutes}{if $firstElement != 'minutes' && $lastElement == 'minutes'} and {/if}{if $minutes > 1}{#$minutes} minutes{else}one minute{/if}{/if}]]></item>
+ <item name="wcf.date.interval.hours.plain"><![CDATA[{if $hours > 1}{#$hours} hours{else}one hour{/if}]]></item>
+ <item name="wcf.date.interval.minutes.plain"><![CDATA[{if $minutes > 1}{#$minutes} minutes{else}one minute{/if}]]></item>
+ <item name="wcf.date.interval.months.plain"><![CDATA[{if $months > 1}{#$months} months{else}one Month{/if}]]></item>
+ <item name="wcf.date.interval.weeks.plain"><![CDATA[{if $weeks > 1}{#$weeks} weeks{else}one week{/if}]]></item>
+ <item name="wcf.date.interval.years.plain"><![CDATA[{if $years > 1}{#$years} years{else}one year{/if}]]></item>
+
<!-- variables for time periods -->
<item name="wcf.date.period.older"><![CDATA[Older]]></item>
<item name="wcf.date.period.today"><![CDATA[Today]]></item>
<item name="wcf.paidSubscription.confirmTOS"><![CDATA[I agree to the <a href="{PAID_SUBSCRIPTION_TOS_URL}">Terms of Service</a>]]></item>
<item name="wcf.paidSubscription.button.moreInformation"><![CDATA[More Details]]></item>
<item name="wcf.paidSubscription.expiringSubscription.notification.title"><![CDATA[Expiring Subscription]]></item>
- <item name="wcf.paidSubscription.expiringSubscription.notification.message"><![CDATA[Your subscription “{$userNotificationObject->getTitle()}” will expire {$userNotificationObject->endDate|dateDiff:$notification->time:false:true} (on {$userNotificationObject->endDate|date:'F jS'}).]]></item>
+ <item name="wcf.paidSubscription.expiringSubscription.notification.message"><![CDATA[Your subscription “{$userNotificationObject->getTitle()}” will expire {$userNotificationObject->endDate|dateDiff:$notification->time:false:"format_sentence"} (on {$userNotificationObject->endDate|date:'F jS'}).]]></item>
</category>
<category name="wcf.payment">