Convert seconds to compound duration: Difference between revisions
Content added Content deleted
Simple9371 (talk | contribs) (Made this a normal task. I think this is the time... but feel free to undo this action if necessary.) |
(→{{header|Tcl}}: Added zkl) |
||
Line 448: | Line 448: | ||
Ok! sec2str 86400 = 1 d |
Ok! sec2str 86400 = 1 d |
||
Ok! sec2str 6000000 = 9 wk, 6 d, 10 hr, 40 min</pre> |
Ok! sec2str 6000000 = 9 wk, 6 d, 10 hr, 40 min</pre> |
||
=={{header|zkl}}== |
|||
<lang zkl>fcn toWDHMS(sec){ //-->(wk,d,h,m,s) |
|||
r,b:=List(),0; |
|||
foreach u in (T(60, 60, 24, 7)){ |
|||
sec,b=sec.divr(u); |
|||
r.append(b); |
|||
} |
|||
r.reverse(); |
|||
}</lang> |
|||
<lang zkl>units:=T("wk","d","hr","min","sec"); |
|||
foreach s in (T(7259,86400,6000000)){ |
|||
toWDHMS(s).zip(units).pump(List,fcn([(t,u)]){ t and "%d %s".fmt(t,u) or "" }) |
|||
.filter().concat(", ").println(); |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
2 d, 59 min |
|||
1 wk |
|||
6 wk, 10 d, 40 hr |
|||
</pre> |