@DeletedUser40526905 (talk | contribs) (Missed a brace) |
Skylord1496 (talk | contribs) mNo edit summary |
||
(19 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
+ | <includeonly>{{#vardefine:input|{{{1|}}}}}<!-- |
||
− | <includeonly>{{#vardefine:input|{{{1|}}}{{#vardefine:time|{{#var:input}}}}{{#vardefine:days|{{#expr:({{#var:time}} - {{#var:time}} mod 86400) / 86400}}}}{{#vardefine:time|{{#expr:{{#var:time}} - {{#var:days}} * 86400}}}}{{#vardefine:hours|{{#expr:({{#var:time}} - {{#var:time}} mod 3600) / 3600}}}}{{#vardefine:time|{{#expr:{{#var:time}} - {{#var:hours}} * 3600}}}}{{#vardefine:minutes|{{#expr:({{#var:time}} - {{#var:time}} mod 60) / 60}}}}{{#vardefine:seconds|{{#expr:{{#var:time}} - {{#var:minutes}} * 60}}}}{{#ifexpr: {{#var:input}} >= 86400 | {{#var:days}}: }}{{#ifexpr: {{#var:input}} >= 3600 | {{#ifexpr: {{#var:input}} < 86400 | {{#var:hours}} | {{#pad:{{#var:hours}}|2|0|left}}: }} }}{{#ifexpr: {{#var:input}} >= 60 | {{#ifexpr: {{#var:input}} < 3600 | {{#var:minutes}} | {{#pad:{{#var:minutes}}|2|0|left}}: }} }}{{#ifexpr: {{#var:input}} < 60 | {{#var:seconds}} | {{#pad:{{#var:seconds}}|2|0|left}} }}</includeonly><noinclude> |
||
+ | -->{{#vardefine:time|{{#var:input}}}}<!-- |
||
− | == Documentation == |
||
+ | -->{{#vardefine:days|{{#expr:floor({{#var:time}} / 86400)}}}}<!-- |
||
− | Formats a duration given in seconds. |
||
+ | -->{{#vardefine:hourstotal|{{#expr:floor({{#var:time}} / 3600)}}}}<!-- |
||
− | |||
+ | -->{{#vardefine:time|{{#expr:{{#var:time}} - {{#var:days}} * 86400}}}}<!-- |
||
− | <nowiki>{{duration|140}}</nowiki> |
||
+ | -->{{#vardefine:hours|{{#expr:floor({{#var:time}} / 3600)}}}}<!-- |
||
+ | -->{{#vardefine:time|{{#expr:{{#var:time}} - {{#var:hours}} * 3600}}}}<!-- |
||
+ | -->{{#vardefine:minutes|{{#expr:floor({{#var:time}} / 60)}}}}<!-- |
||
+ | -->{{#vardefine:seconds|{{#expr:{{#var:time}} - {{#var:minutes}} * 60 round 3}}}}<!-- |
||
+ | -->{{#if:{{{2|}}}|<!-- with second parameter, i.e. dd:hh:mm:ss |
||
+ | -->{{#ifeq:{{{2|}}}|hhmm|<!-- with specific second parameter hhmm |
||
+ | -->{{#ifexpr: {{#var:input}} >= 3600 | {{#var:hourstotal}}: }}<!-- |
||
+ | -->{{#ifexpr: {{#var:input}} >= 60 | {{#ifexpr: {{#var:input}} < 3600 | {{#var:minutes}} | {{padleft:{{#var:minutes}}|2|0}} }} }} |
||
+ | |{{#ifeq:{{{2|}}}|ddhhmm|<!-- with specific second parameter ddhhmm |
||
+ | -->{{#ifexpr: {{#var:input}} >= 86400 | {{#var:days}}d }} <!-- |
||
+ | -->{{#ifexpr: {{#var:input}} >= 3600 | {{#ifexpr: {{#var:input}} < 86400 | {{#var:hours}}: | {{padleft:{{#var:hours}}|2|0}}: }} | 0: }}<!-- |
||
+ | -->{{#ifexpr: {{#var:input}} >= 60 | {{#ifexpr: {{#var:input}} < 3600 | {{#var:minutes}} | {{padleft:{{#var:minutes}}|2|0}} }} }} |
||
+ | |<!-- with non-specific second parameter, i.e. f |
||
+ | -->{{#ifexpr: {{#var:input}} >= 86400 | {{#var:days}}: }}<!-- |
||
+ | -->{{#ifexpr: {{#var:input}} >= 3600 | {{#ifexpr: {{#var:input}} < 86400 | {{#var:hours}}: | {{padleft:{{#var:hours}}|2|0}}: }} }}<!-- |
||
+ | -->{{#ifexpr: {{#var:input}} >= 60 | {{#ifexpr: {{#var:input}} < 3600 | {{#var:minutes}}: | {{padleft:{{#var:minutes}}|2|0}}: }} }}<!-- |
||
+ | -->{{#ifexpr: {{#var:input}} < 60 | {{#var:seconds}} | {{padleft:{{#var:seconds}}|2|0}} }} |
||
+ | }}}}|<!-- without second parameter, i.e. like 1d 2h 3m 4s |
||
+ | -->{{#ifexpr: {{#var:input}} >= 86400 | {{#var:days}}d }} <!-- |
||
+ | -->{{#ifexpr: {{#var:input}} >= 3600 | {{#ifexpr: {{#var:hours}} > 0 | {{#var:hours}}h | }} }} <!-- |
||
+ | -->{{#ifexpr: {{#var:input}} >= 60 | {{#ifexpr: {{#var:minutes}} > 0 | {{#var:minutes}}m | }} }} <!-- |
||
+ | -->{{#ifexpr: {{#var:seconds}} > 0 | {{#var:seconds}}s | }} |
||
+ | }}</includeonly><noinclude>{{doc}} |
||
[[Category:Formatting templates]]</noinclude> |
[[Category:Formatting templates]]</noinclude> |
Revision as of 19:29, 12 July 2019
Documentation
[purge]
Formats a duration given in seconds. Seconds will be rounded to 3 digits.
Usage
{{duration|s|format}}
- If the second parameter "hhmm" is given , the format will be like hh:mm, hh been the total number of hours including days.
- If the second parameter "ddhhmm" is given , the format will be like dd hh:mm if the duration is longer than a day, otherwise the format will be like hh:mm.
- If any other second parameter is given (any non-whitespace character), the format will be like dd:hh:mm:ss.
- If the second parameter is empty, the format will be like 1d 4h 23m 2s.
Examples
{{duration|20}}
creates 20s{{duration|140}}
creates 2m 20s{{duration|86406}}
creates 1d 6s{{duration|20|f}}
creates 20{{duration|140|f}}
creates 2:20{{duration|86406|f}}
creates 1:00:00:06{{duration|118518.515625}}
creates 1d 8h 55m 18.516s{{duration|118518.515625|hhmm}}
creates 32:55{{duration|118518.515625|ddhhmm}}
creates 1d 08:55{{duration|118518.515625|f}}
creates 1:08:55:18.516