zsh-users
 help / color / mirror / code / Atom feed
* s2hms
@ 2017-10-18 22:21 Emanuel Berg
  2017-10-19  8:49 ` s2hms Marc Chantreux
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2017-10-18 22:21 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-10-20 11:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-18 22:21 s2hms Emanuel Berg
2017-10-19  8:49 ` s2hms Marc Chantreux
2017-10-19 13:03   ` s2hms Emanuel Berg
2017-10-20 10:26     ` s2hms Marc Chantreux
2017-10-20 11:27       ` s2hms Emanuel Berg

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).