formatDuration
Writes a number of seconds as text: 1h 30m, 1 hour, 30 minutes or 1:30:00.
Details #
formatDuration(seconds, style?) takes one or two arguments and returns text.
short(the default):1h 30m. Units that are zero are left out, and zero is0s.long:1 hour, 30 minutes.clock:1:30:00, or30:05under an hour.
A negative number gets a leading -. Seconds are rounded to whole seconds.
Parameters #
Takes 1 to 2 arguments.
{{ formatDuration(text, b?) }}
Examples #
formatDuration(5400)→
1h 30mformatDuration(5400, "long")→
1 hour, 30 minutesformatDuration(parseDuration("90 min"), "clock")→
1:30:00Gotchas #
Any other style is an error:
formatDuration() style should be short, long or clock.Short form counts days (
2d 3h) and goes no higher.