Update: Fixed last bugs and limitations:
{{#ifexpr:{{{1}}}>=86400|{{#expr: trunc({{{1}}}/86400)}} day{{#ifexpr:{{#expr: trunc({{{1}}}/86400)}}=1||s}}}}<!-- HOURS -->{{#ifexpr:({{{1}}}-(86400*trunc({{{1}}}/86400)))>=3600|{{#ifexpr:{{#expr: trunc({{{1}}}/86400)}}=0|| }}{{#expr: trunc(({{{1}}}-(86400* trunc({{{1}}}/86400)))/3600)}} hour{{#ifexpr:{{#expr: trunc(({{{1}}}-(86400*trunc({{{1}}}/86400)))/3600)}}=1||s}}}}<!-- MINUTES -->{{#ifexpr:(({{{1}}}-(86400*trunc({{{1}}}/86400)))-(3600*trunc(({{{1}}}-(86400*trunc({{{1}}}/86400)))/3600)))>=60|{{#ifexpr:{{#expr: trunc(({{{1}}}-(86400*trunc({{{1}}}/86400)))/3600)}}=0|{{#ifexpr:{{#expr: trunc({{{1}}}/86400)}}=0|| }}| }}{{#expr: trunc((({{{1}}}-(86400*trunc({{{1}}}/86400)))-(3600* trunc(({{{1}}}-(86400*trunc({{{1}}}/86400)))/3600)))/60)}} min{{#ifexpr:{{#expr:trunc((({{{1}}}-(86400*trunc({{{1}}}/86400)))-(3600*trunc(({{{1}}}-(86400* trunc({{{1}}}/86400)))/3600)))/60)}}=1||s}}}}<!-- SECONDS -->{{#ifexpr:{{#expr:(({{{1}}}-(86400*trunc({{{1}}}/86400)))-(3600*trunc(({{{1}}}-(86400*trunc({{{1}}}/86400)))/3600)))-(60*trunc((({{{1}}}-(86400*trunc({{{1}}}/86400)))-(3600*trunc(({{{1}}}-(86400*trunc({{{1}}}/86400)))/3600)))/60))}}=0||{{#ifexpr:{{#expr:trunc((({{{1}}}-(86400*trunc({{{1}}}/86400)))-(3600*trunc(({{{1}}}-(86400* trunc({{{1}}}/86400)))/3600)))/60)}}=0|{{#ifexpr:{{#expr: trunc(({{{1}}}-(86400*trunc({{{1}}}/86400)))/3600)}}=0|{{#ifexpr:{{#expr: trunc({{{1}}}/86400)}}=0|| }}| }}| }}{{#expr:(({{{1}}} - (86400* trunc({{{1}}} / 86400) )) - (3600* trunc(({{{1}}} - (86400* trunc({{{1}}} / 86400) )) / 3600) )) - (60* trunc(( ( {{{1}}} - (86400* trunc({{{1}}} / 86400) )) - (3600* trunc(({{{1}}} - (86400* trunc({{{1}}} / 86400) )) / 3600) )) / 60)) }} second{{#ifexpr: {{#expr: (({{{1}}} - (86400* trunc({{{1}}} / 86400) )) - (3600* trunc(({{{1}}} - (86400* trunc({{{1}}} / 86400) )) / 3600) )) - (60* trunc(( ( {{{1}}} - (86400* trunc({{{1}}} / 86400) )) - (3600* trunc(({{{1}}} - (86400* trunc({{{1}}} / 86400) )) / 3600) )) / 60)) }} = 1||s}}}}
I know.
I tested adding a space in that location and it worked fine. Can you give me an example of when it won't work, so I can test it for myself?
Without the ifexpr on the space code the space will remain when day/second for example get displayed. I think all bugs are fixed now. I create the template over here and named it timedisplay:
Spacecheck
*"{{Timedisplay|{{#expr: 1*60*60*24}}}}" *"{{Timedisplay|{{#expr: 1*60*60*24+1}}}}" *"{{Timedisplay|{{#expr: 1*60*60*24+60}}}}" *"{{Timedisplay|{{#expr: 1*60*60*24+60+1}}}}" *"{{Timedisplay|{{#expr: 1*60*60*24+60*60}}}}" *"{{Timedisplay|{{#expr: 1*60*60*24+60*60+1}}}}" *"{{Timedisplay|{{#expr: 1*60*60}}}}" *"{{Timedisplay|{{#expr: 1*60*60+1}}}}" *"{{Timedisplay|{{#expr: 1*60*60+60}}}}" *"{{Timedisplay|{{#expr: 1*60*60+60+1}}}}" *"{{Timedisplay|{{#expr: 1*60}}}}" *"{{Timedisplay|{{#expr: 1*60+1}}}}" *"{{Timedisplay|{{#expr: 1}}}}" *"{{Timedisplay|{{#expr: 0}}}}"
I have updated Template:Timedisplay with the changes I suggested, and added a series of example tests to that page.
Here are the tests again:
I'm not seeing any problem with the spaces.
edit: I added quotes around the template, and I'm now seeing a leading space - is this what you were talking about?
Nop, this will not fix the space bug. You caused it again:
It's not really an large problem but in case with tables it does.
Thanks, I understand the problem now, and I agree with your solution. Good work!
Thanks, I discover the problem myself when I implemented on my wiki. This seems the only possible fix.
Thank you for the trunc function inside the template. I didn't known that function before.
It certainly makes things easier :)
You might like to read through http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions and related pages to learn about anything else you might need to use later.
On http://meta.wikimedia.org/wiki/Help:Magic_words there's a function "plural", which you could use instead of your "=1" check, but there's no real need to change it.
edit: after finding out that the plural: function wasn't very useful, I created a custom "plural" template, how I use it is {{plural| units | min | mins }} and it will return "1 min" or "2 mins", which saves a little space.
But I figure since you wanted a single template solution anyway, you probably don't want to create extra templates like that.