Convert seconds to compound duration: Difference between revisions

Content added Content deleted
(Add CLU)
Line 1,294: Line 1,294:
"9 wk, 6 d, 10 hr, 40 min"
"9 wk, 6 d, 10 hr, 40 min"
</pre>
</pre>

=={{header|CLU}}==
<lang clu>duration = proc (s: int) returns (string)
own units: array[string] := array[string]$["wk","d","hr","min","sec"]
own sizes: array[int] := array[int]$[2:7,24,60,60]
d: string := ""
r: int
for i: int in int$from_to_by(5,1,-1) do
begin
r := s // sizes[i]
s := s / sizes[i]
end except when bounds:
r := s
end
if r ~= 0 then
d := ", " || int$unparse(r) || " " || units[i] || d
end
end
return(string$rest(d,3))
end duration

start_up = proc ()
po: stream := stream$primary_output()
tests: array[int] := array[int]$[7259,86400,6000000]
for test: int in array[int]$elements(tests) do
stream$putl(po, int$unparse(test) || " => " || duration(test))
end
end start_up</lang>
{{out}}
<pre>7259 => 2 hr, 59 sec
86400 => 1 d
6000000 => 9 wk, 6 d, 10 hr, 40 min</pre>


=={{header|COBOL}}==
=={{header|COBOL}}==