Anonymous user
Convert seconds to compound duration: Difference between revisions
Convert seconds to compound duration (view source)
Revision as of 19:23, 4 October 2020
, 3 years agoadded whitespace and indentation of tables.
m (added whitespace and indentation of tables.) |
|||
Line 4:
;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.
This is detailed below (e.g., "<code>2 hr, 59 sec</code>").
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>
:::::{| class="wikitable"▼
▲<li>The following five units should be used:
▲{| class="wikitable"
|-
! unit
Line 51 ⟶ 57:
| minute
| <code style="background:#eee">min</code>
| 1
|-
| second
Line 57 ⟶ 63:
|
|}
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>▼
▲
<hr style="margin:1em 0;"/>
<br><br>
|