Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

s2hms



I just wrote a small interface to units(1).
Does it look good to you?

Try for example

    $ s2hms 500
    8m 20s

Sounds about right...

s2hms () {
    local secs=$1

    local time_string
    time_string=$(units -t "$secs s" hms)

    local -a data
    data=("${(@s/;/)time_string}")
    local h=$data[1]
    local m=$data[2]
    local s=$data[3]

    local out
    [[ $h > 0 ]] && out ="${h}h "
    [[ $m > 0 ]] && out+="${m}m "
    [[ $s > 0 ]] && out+="${s}s"
    echo $out
}

-- 
underground experts united
http://user.it.uu.se/~embe8573



Messages sorted by: Reverse Date, Date, Thread, Author