Template:Duration

来自Terraria Wiki
跳到导航 跳到搜索
This template is i18n-ready, which means it is easy to localize for different languages. Please see I18n & l10n for templates to learn more.
See Template:Duration/l10n for the localization of this template.
Template-info.svg 文档 以下文档来自Template:Duration/doc。(编辑 | 历史

Format a time value, input in seconds.

Usage

{{ duration | <time in seconds/ticks> | <maximum unit> | round = <rounding level> | raw<seconds/minutes/hours/days/weeks> = <non-numerical time> }}

First unnamed parameter

Number, any valid {{#expr:}} string is accepted. By default interpreted as time in seconds, unless the number is followed by any of the strings t/tick/ticks, in which case the value is interpreted as time in ticks.[1]

Second unnamed parameter

Greatest unit of the output. Can be any of seconds, minutes (default), hours, days, and weeks, or s, m, h, d, and w for short, respectively.

round

Rounding level for decimal seconds, 2 by default.

rawseconds, rawminutes, rawhours, rawdays, rawweeks

One of these parameters can be used to prevent any calculations and formatting (hence "raw") and just display the given time and unit. This is useful if the input time is not purely numerical (e.g. not a valid {{#expr:}} string) and would thus normally result in an error, e.g. a time range like "1–3 seconds". Only one out of these five parameters can be used. All other parameters are ignored if one of these is used.

Notes

  • The template does not support specifying a lowest unit of the output. Instead, this can easily be achieved by rounding the number of seconds divided by the number of seconds in the target unit, then multiplying that value by the target unit again. For example, to display 3661 (1 小时 1 分钟 1 秒) in only hours and minutes, use (3661 / 60 round 0) * 60. To round down or up, use floor() or ceil() instead of round 0, respectively. To set the lowest unit to hours, use 3600 instead of 60, and 86400 for days. See below for examples.

Examples

Code Result
{{duration|41}} 41 秒 FAIL! (expected: 41 seconds )
{{duration|40.75}} 40.75 秒 FAIL! (expected: 40.75 seconds )
{{duration|90}} 1 分钟 30 秒 FAIL! (expected: 1 minute 30 seconds )
{{duration|1800}} 30 分钟 FAIL! (expected: 30 minutes )
{{duration|7201}} 120 分钟 1 秒 FAIL! (expected: 120 minutes 1 second )
{{duration|604800}} 10,080 分钟 FAIL! (expected: 10,080 minutes )
With unit
{{duration|604800|weeks}} 1 星期 FAIL! (expected: 1 week )
{{duration|7201|weeks}} 2 小时 1 秒 FAIL! (expected: 2 hours 1 second )
{{duration|604800|d}} 7 天 FAIL! (expected: 7 days )
{{duration|7201|w}} 2 小时 1 秒 FAIL! (expected: 2 hours 1 second )
Various inputs
{{duration|2/3}} 0.67 秒 FAIL! (expected: 0.67 seconds )
{{duration|2/3|round=6}} 0.666667 秒 FAIL! (expected: 0.666667 seconds )
{{duration|(35/11 mod 2) - (10^-2 / pi*3) + ceil(21/6)}} 4.99 秒 FAIL! (expected: 4.99 seconds )
{{duration|{{#time:U|+3 days 2 hours 44 minutes 23 seconds}}-{{#time:U}}|days}} 3 天 2 小时 44 分钟 24 秒
{{duration|{{#time:U|+2 days 37 hours 98 minutes 63 seconds}}-{{#time:U}}|hours}} 86 小时 39 分钟 4 秒
{{duration|-41}} −41 秒 FAIL! (expected: −41 seconds )
{{duration|-3601|days}} −1 小时 1 秒 FAIL! (expected: −1 hour 1 second )
Near-zero behavior
{{duration|0}} 0 秒 FAIL! (expected: 0 seconds )
{{duration|0.001}} 0 秒 FAIL! (expected: 0 seconds )
{{duration|-0.001}} −0 秒 FAIL! (expected: −0 seconds )
{{duration|0.001|round=5}} 0.001 秒 FAIL! (expected: 0.001 seconds )
Tick[1] input
{{duration|60t}} 1 秒 FAIL! (expected: 1 second )
{{duration|20tick}} 0.33 秒 FAIL! (expected: 0.33 seconds )
{{duration| 30 Ticks }} 0.5 秒 FAIL! (expected: 0.5 seconds )
{{duration|140 ticks|round=4}} 2.3333 秒 FAIL! (expected: 2.3333 seconds )
Lowest output unit
{{duration|694921|days}} 8 天 1 小时 2 分钟 1 秒 FAIL! (expected: 8 days 1 hour 2 minutes 1 second )
{{duration|(694921 / 3600 round 0) * 3600|days}} 8 天 1 小时 FAIL! (expected: 8 days 1 hour )
{{duration|ceil(694921 / 3600) * 3600|days}} 8 天 2 小时 FAIL! (expected: 8 days 2 hours )
{{duration|(694921 / 86400 round 0) * 86400|days}} 8 天 FAIL! (expected: 8 days )
"Raw" input
{{duration|rawseconds=2.5–6.5}} 2.5–6.5 秒 FAIL! (expected: 2.5–6.5 seconds )
{{duration|rawseconds=0.5–1}} 0.5–1 秒 FAIL! (expected: 0.5–1 second )
{{duration|rawhours=12–24}} 12–24 小时 FAIL! (expected: 12–24 hours )

References

  1. 1.0 1.1 嘀嗒是可由软件计数的时间单位。泰拉瑞亚的大多数更新逻辑都会每嘀嗒发生一次。一个嘀嗒的长度为 1/60 秒,因此一秒钟内有 60 嘀嗒,一分钟内有 3600 嘀嗒。