Difference between revisions of "Template:Time-support"

From Ring of Brodgar
(+show zero minutes (nosec case) ... (might need other case to limit output to hours and minutes only ... later))
(+hm limited output case ("Hh Mm") - (ditch leading NoneBreakingSpace))
 
Line 5: Line 5:
 
| {{#if:{{{yd|}}}
 
| {{#if:{{{yd|}}}
 
   | {{#iferror: {{#time:z|@{{{yd}}} }}
 
   | {{#iferror: {{#time:z|@{{{yd}}} }}
     |{{error|Bad Unix-time input(a) (Integer only)|Template:Time-support: }}</strong>
+
     | {{error|Bad Unix-time input(a) (Integer only)|Template:Time-support: }}</strong>
     |&nbsp;{{
+
     | {{
 
       #ifexpr: {{#time:Y|@{{{yd}}} }} > 1970
 
       #ifexpr: {{#time:Y|@{{{yd}}} }} > 1970
 
       | {{#ifexpr: {{#time:Y|@{{{yd}}} }} > 1971 | {{#expr:{{#time:Y|@{{{yd}}} }}-1970}}&nbsp;years&nbsp;| 1&nbsp;year&nbsp;}}
 
       | {{#ifexpr: {{#time:Y|@{{{yd}}} }} > 1971 | {{#expr:{{#time:Y|@{{{yd}}} }}-1970}}&nbsp;years&nbsp;| 1&nbsp;year&nbsp;}}
Line 16: Line 16:
 
   | {{#if:{{{1|}}}
 
   | {{#if:{{{1|}}}
 
     | {{#iferror: {{#time:z|@{{{1}}} }}
 
     | {{#iferror: {{#time:z|@{{{1}}} }}
       |{{error|Bad Unix-time input(b) (Integer only)|Template:Time-support: }}
+
       | {{error|Bad Unix-time input(b) (Integer only)|Template:Time-support: }}
       |&nbsp;{{
+
    | {{#ifeq:{{{2|}}}|hm
        #ifexpr: {{#time:z|@{{{1}}} }} != 0 | {{#time:z|@{{{1}}} }}d&nbsp;}}{{
+
      | {{#expr:trunc({{{1}}}/3600)}}h {{#expr:{{#time:i|@{{{1}}} }} + ({{#time:s|@{{{1}}} }} >= 30) }}m
        #ifexpr: {{#time:G|@{{{1}}} }} != 0 | {{#time:G|@{{{1}}} }}h&nbsp;}}{{
+
       | {{
#if:{{{nosec|}}}
+
          #ifexpr: {{#time:z|@{{{1}}} }} != 0 | {{#time:z|@{{{1}}} }}d&nbsp;}}{{
|{{#expr:{{#time:i|@{{{1}}} }} + ({{#time:s|@{{{1}}} }} >= 30) }}m&nbsp;
+
          #ifexpr: {{#time:G|@{{{1}}} }} != 0 | {{#time:G|@{{{1}}} }}h&nbsp;}}{{
|{{#ifexpr: {{#time:i|@{{{1}}} }} != 0 | {{#expr:{{#time:i|@{{{1}}} }} }}m&nbsp;}}{{
+
          #if:{{{nosec|}}}
  #ifexpr: {{#time:s|@{{{1}}} }} != 0 | {{#expr:{{#time:s|@{{{1}}} }} }}s&nbsp;}}
+
          | {{#expr:{{#time:i|@{{{1}}} }} + ({{#time:s|@{{{1}}} }} >= 30) }}m&nbsp;
}}
+
  | {{#ifexpr: {{#time:i|@{{{1}}} }} != 0 | {{#expr:{{#time:i|@{{{1}}} }} }}m&nbsp;}}{{
 +
              #ifexpr: {{#time:s|@{{{1}}} }} != 0 | {{#expr:{{#time:s|@{{{1}}} }} }}s&nbsp;}}
 +
          }}
 
       }}
 
       }}
 +
    }}
 
     |<error:no input>
 
     |<error:no input>
 
     }}
 
     }}
Line 44: Line 47:
 
:26) foo<code>{{ {{PAGENAME}}|h=3.11}}</code>bar - foo<code>{{ {{PAGENAME}}|{{ {{PAGENAME}}|h=3.11}}|nosec=x}}</code>bar
 
:26) foo<code>{{ {{PAGENAME}}|h=3.11}}</code>bar - foo<code>{{ {{PAGENAME}}|{{ {{PAGENAME}}|h=3.11}}|nosec=x}}</code>bar
 
:27) foo<code>{{ {{PAGENAME}}|h=27.0}}</code>bar - foo<code>{{ {{PAGENAME}}|{{ {{PAGENAME}}|h=27.0}}|nosec=x}}</code>bar
 
:27) foo<code>{{ {{PAGENAME}}|h=27.0}}</code>bar - foo<code>{{ {{PAGENAME}}|{{ {{PAGENAME}}|h=27.0}}|nosec=x}}</code>bar
 +
:28) foo<code>{{ {{PAGENAME}}|d=1|h=10|m=17|s=36}}</code>bar - foo<code>{{ {{PAGENAME}}|{{ {{PAGENAME}}|d=1|h=10|m=17|s=36}}|hm}}</code>bar
 
:30) foo<code>{{ {{PAGENAME}}|yd=0}}</code>bar (''ignored case'')
 
:30) foo<code>{{ {{PAGENAME}}|yd=0}}</code>bar (''ignored case'')
 
:31) foo<code>{{ {{PAGENAME}}|yd={{#expr:60*60*24}}}}</code>bar
 
:31) foo<code>{{ {{PAGENAME}}|yd={{#expr:60*60*24}}}}</code>bar

Latest revision as of 01:55, 8 June 2019

01) foo<error:no input>bar
11) foo2m 3s bar
12) foo20m 34s bar
13) foo3h 25m 45s bar
14) foo1d 10h 17m 36s bar
21) foo123456bar - foo1d 10h 17m 36s bar
22) foo86400bar - foo1d 
23) foo36000bar - foo10h bar
24) foo1020bar - foo17m bar
25) foo36bar - foo36s bar
26) foo11196bar - foo3h 7m bar
27) foo97200bar - foo1d 3h 0m bar
28) foo123456bar - foo34h 18mbar
30) foobar (ignored case)
31) foo1 day bar
32) foo1 year bar
33) foo3 years 332 days bar
91) fooTemplate:Time-support: Bad Unix-time input(a) (Integer only)bar
92) fooTemplate:Time-support: Bad Unix-time input(b) (Integer only)bar