zsh-users
 help / color / mirror / code / Atom feed
From: Emanuel Berg <moasen@zoho.com>
To: zsh-users@zsh.org
Subject: s2hms
Date: Thu, 19 Oct 2017 00:21:55 +0200	[thread overview]
Message-ID: <86h8uw14ho.fsf@zoho.com> (raw)

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


             reply	other threads:[~2017-10-18 22:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18 22:21 Emanuel Berg [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86h8uw14ho.fsf@zoho.com \
    --to=moasen@zoho.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).