Formats a number (sec) in human readable way with hours, minutes and (mili- / micro-) seconds.


Syntax

format_duration ($number, bool $withSec = false, string $mode = 'short'): string

  • $number - int|float|string|null
    The number to format.

  • $withSec
    If TRUE the seconds will be printed, too. Else silently discarded. No rounding then is applied.

  • $mode
    "short" - Formats the number in the syntax, llike:   <hh>:<mm>[:<ss>]
    "mid" - Number will be formatted like:   <hh>h <mm>m [<ss>s]
    Additionally this handles milliseconds (ms) and microseconds (us) - if $withSec enabled.
    Examples:   "1h 3s",  "5m",  "35ms"


Examples


{{ hublify.format_duration( 65 ) }}                     =>    00:01

{{ hublify.format_duration( 65, false, "mid" ) }}       =>    1m
{{ hublify.format_duration( 65, true, "mid" ) }}        =>    1m 5s

{{ hublify.format_duration( 0.5123, true, "mid" ) }}    =>    512ms