Convert seconds to compound duration: Difference between revisions
Content added Content deleted
m (→{{header|AppleScript}}: Tidied.) |
(add Standard ML) |
||
Line 3,473: | Line 3,473: | ||
6000000 sec = 9 wk, 6 d, 10 hr, 40 min |
6000000 sec = 9 wk, 6 d, 10 hr, 40 min |
||
</pre> |
</pre> |
||
=={{header|Standard ML}}== |
|||
<lang sml>fun compoundDuration seconds = |
|||
let |
|||
fun fmtNonZero (0, s) = NONE |
|||
| fmtNonZero (x, s) = SOME (Int.toString x ^ " " ^ s) |
|||
fun divMod (divisor, (duration, list)) = |
|||
(duration div divisor, duration mod divisor :: list) |
|||
val (weeks, subUnits) = foldl divMod (seconds, []) [60, 60, 24, 7] |
|||
in |
|||
(String.concatWith ", " |
|||
o List.mapPartial fmtNonZero |
|||
o ListPair.zip) (weeks :: subUnits, ["wk", "d", "hr", "min", "sec"]) |
|||
end |
|||
val () = app (fn s => print (compoundDuration s ^ "\n")) [7259, 86400, 6000000]</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |