Definition: |
string res = elapsed(atom s)
-- or -- string res = elapsed_short(atom s) |
Description: | Convert a time in seconds to a human-readable string. |
Comments: |
Technically this is not part of timedate but a standalone autoinclude (builtins/pelapsed.e)
This is a trivial routine designed for general purpose use/approximations; for more precise timings, such as benchmark results, sprintf("%3.2fs",s) is probably more appropriate. A type check error occurs if s exceeds 100 billion years (probably fixable, but left as is to catch bad input). The short form returns a string in the format (([minus][N year[s], ][N day[s], ]|[-])[N:[0]]N:[0]N|[-]Ns) For long form results, see Examples below. To explain that short form value more explicitly: if the result contains no ':', it is seconds (and has a trailing s), eg "3s" if the result contains one ':', it is minutes:seconds (':' at [-3]), eg "2:30" if the result contains two ':', it is hours:minutes:seconds (':' at [-6,-3]), eg "2:30:00" (if you want two and a half hours to appear as "2:30", chop 3 chars off the result!) if required, the result is prefixed with "y year[s]" and "d day[s]", ie in longhand. Negative year and day values are prefixed with "minus ", negative hours/mins/secs with (just the one) "-". Neither routine makes any attempt to express duration in weeks, months, decades, centuries, or millenia. |
Example: |
?elapsed(12.34) -- "12.34s" ?elapsed_short(12.34) -- "12s" ?elapsed(120) -- "2 minutes" ?elapsed_short(120) -- "2:00" ?elapsed(1234) -- "20 minutes and 34s" ?elapsed_short(1234) -- "20:34" ?elapsed(123456) -- "1 day, 10 hours, 17 minutes and 36s" ?elapsed_short(123456) -- "1 day, 10:17:36" ?elapsed(120*60) -- "2 hours" ?elapsed_short(120*60) -- "2:00:00" |