Convert seconds to compound duration: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: another iff) |
m (→version 2: changed subroutine into a function, added whitespace to the output.) |
||
Line 1,536:
parse arg @; if @='' then @=7259 86400 6000000 /*Not specified? Then use the default.*/
do j=1 for words(@); z=word(@,
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
convSec: parse arg x /*obtain a number from the argument. */
w=timeU( 60*60*24*7, 'wk' )
d=timeU( 60*60*24 , 'd' )
h=timeU( 60*60 , 'hr' )
m=timeU( 60 , 'min' )
s=timeU( 1 , 'sec' )
if x\==0 then s=word(s 0, 1) + x 'sec'
return $▼
▲ return
/*──────────────────────────────────────────────────────────────────────────────────────*/
timeU: parse arg u,$; _=x%u; if _==0 then return ''; x=x-_*u; return _ $","</lang>
'''output''' when using the default (internal) inputs:
<pre>
7259 seconds: 2 hr, 59 sec
86400 seconds: 1 d
6000000 seconds: 9 wk, 6 d, 10 hr, 40 min
</pre>
'''output''' when using the inputs: <tt> 1800.7 123.50 123.00 0.00 </tt>
<pre>
1800.7 seconds: 30 min, 0.7 sec
123.50 seconds: 2 min, 3.50 sec
123.00 seconds: 2 min, 3 sec
0.00 seconds: 0 sec
</pre>
|