Convert seconds to compound duration: Difference between revisions
Content added Content deleted
m (→{{header|Rust}}: Updated decription) |
(Added uBasic/4tH version) |
||
Line 1,025: | Line 1,025: | ||
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|uBasic/4tH}}== |
|||
Since uBasic/4tH is integer-only, it is hard to return a string. However, it is capable to transform an integer value as required. |
|||
<lang>Proc _CompoundDuration(7259) |
|||
Proc _CompoundDuration(86400) |
|||
Proc _CompoundDuration(6000000) |
|||
End |
|||
_CompoundDuration Param(1) ' Print compound seconds |
|||
a@ = FUNC(_Compound(a@, 604800, _wk)) |
|||
a@ = FUNC(_Compound(a@, 86400, _d)) |
|||
a@ = FUNC(_Compound(a@, 3600, _hr)) |
|||
a@ = FUNC(_Compound(a@, 60, _min)) |
|||
If a@ > 0 Then Print a@;" sec"; ' Still seconds left to print? |
|||
Print |
|||
Return |
|||
_Compound Param(3) |
|||
Local(2) |
|||
d@ = a@/b@ ' Get main compount |
|||
a@ = a@%b@ ' Leave the rest |
|||
If d@ > 0 Then ' Print the week compound |
|||
Print d@; |
|||
Proc c@ |
|||
If a@ > 0 Then |
|||
Print ", "; ' If something follows, take |
|||
EndIf ' care of the comma |
|||
EndIf |
|||
Return (a@) |
|||
_wk Print " wk"; : Return |
|||
_d Print " d"; : Return |
|||
_hr Print " hr"; : Return |
|||
_min Print " min"; : Return</lang> |
|||
{{out}} |
|||
<pre>2 hr, 59 sec |
|||
1 d |
|||
9 wk, 6 d, 10 hr, 40 min |
|||
0 OK, 0:94</pre> |
|||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
<lang vb> |
<lang vb> |