Convert seconds to compound duration: Difference between revisions

Content added Content deleted
(insert →‎Pascal)
(Added XPL0 example.)
Line 4,022: Line 4,022:


for (s in [7259, 86400, 6000000]) System.print(duration.call(s))</lang>
for (s in [7259, 86400, 6000000]) System.print(duration.call(s))</lang>

{{out}}
<pre>
2 hr, 59 sec
1 d
9 wk, 6 d, 10 hr, 40 min
</pre>

=={{header|XPL0}}==
<lang XPL0>char Str(80);
func Duration(Sec); \Convert seconds to compound duration
int Sec, Amt, Unit, DoComma, I, Quot;
[Amt:= [7*24*60*60, 24*60*60, 60*60, 60, 1];
Unit:= [" wk", " d", " hr", " min", " sec"];
DoComma:= false;
for I:= 0 to 4 do
[Quot:= Sec/Amt(I);
Sec:= rem(0);
if Quot # 0 then
[if DoComma then Text(8, ", ");
DoComma:= true;
IntOut(8, Quot);
Text(8, Unit(I));
];
];
ChOut(8, $0D); ChOut(8, $8A); \terminating CR+LF
I:= 0;
loop [Str(I):= ChIn(8);
if Str(I) >= $80 then return Str;
I:= I+1;
];
];

[Text(0, Duration(7259));
Text(0, Duration(86400));
Text(0, Duration(6_000_000));
]</lang>


{{out}}
{{out}}