Jump to content

Convert seconds to compound duration: Difference between revisions

m
added whitespace and indentation of tables.
m (added whitespace and indentation of tables.)
Line 4:
;Task:
Write a function or program which:
* &nbsp; takes a positive integer representing a duration in seconds as input (e.g., <code>100</code>), and
* &nbsp; 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>").:
:::* &nbsp; weeks,
:::* &nbsp; days,
:::* &nbsp; hours,
:::* &nbsp; minutes, &nbsp; and
:::* &nbsp; seconds.
 
This is detailed below (e.g., "<code>2 hr, 59 sec</code>").
 
 
<br>
Demonstrate that it passes the following three test-cases:
 
<p style="font-size:115%; margin:1em 0 0.5em 0">'''''Test Cases'''''</p>
 
:::::{| class="wikitable"
|-
! input number
Line 29 ⟶ 36:
<p style="font-size:115%; margin:1em 0 0.5em 0">'''''Details'''''</p>
 
<li>The following five units should be used:
<ul>
:::::{| class="wikitable"
<li>The following five units should be used:
{| class="wikitable"
|-
! unit
Line 51 ⟶ 57:
| minute
| <code style="background:#eee">min</code>
| 1 minutesminute = 60 seconds
|-
| second
Line 57 ⟶ 63:
|
|}
</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>GiveHowever, larger'''only''' unitsinclude precedencequantities overwith smallernon-zero onesvalues asin muchthe as possibleoutput (e.g., return "<code>21 min, 10 secd</code>" and not "<code>0 wk, 1 mind, 700 sec</code>hr, or0 <code>130min, 0 sec</code>")</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>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>
</ul>
 
<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>
<hr style="margin:1em 0;"/>
<br><br>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.