Convert seconds to compound duration: Difference between revisions

m
Replaced all occurrences of "e.g." with "e.g.,"
m (accidentally pasted something)
m (Replaced all occurrences of "e.g." with "e.g.,")
Line 1:
{{task}}
Write a function or program which
* takes a positive integer representing a duration in seconds as input (e.g., <code>100</code>), and
* returns a string which shows the same duration decomposed into weeks, days, hours, minutes, and seconds as detailed below (e.g., "<code>1 min, 40 sec</code>").
 
Demonstrate that it passes the following three test-cases:
Line 55:
</li>
 
<li>However, '''only''' include quantities with non-zero values in the output (e.g., return "<code>1 d</code>" and not "<code>0 wk, 1 d, 0 hr, 0 min, 0 sec</code>").</li>
 
<li>Give larger units precedence over smaller ones as much as possible (e.g., return <code>2 min, 10 sec</code> and not <code>1 min, 70 sec</code> or <code>130 sec</code>)</li>
 
<li>Mimic the formatting shown in the test-cases (quantities sorted from largest unit to smallest and separated by comma+space; value and unit of each quantity separated by space).</li>