From: Marc Chantreux <khatar@phear.org>
To: zsh-users@zsh.org
Subject: Re: s2hms
Date: Thu, 19 Oct 2017 08:49:38 +0000 [thread overview]
Message-ID: <20171019084938.GA11689@aurora-borealis.phear.org> (raw)
In-Reply-To: <86h8uw14ho.fsf@zoho.com>
hello,
you don't need the $data buffer as you can read directly in varibles.
my (untested) version should be more like
s2hms () {
# clean error message when no argument passed
local secs=${1?duration in seconds} it= out=
local -a fields=( h m s )
local -A duration
# duration\[$^fields] is a short for
# duration\[h] duration\[m] duration\[s]
units -t $secs\s hms |
IFS=\; read duration\[$^fields]
# use mathematical context to do math
# also: a value is 0 or >0 so just test if it's >0
for it ($fields)
(( duration[it] )) && out+="$duration[$it]$it"
print $out
}
HTH
regards
--
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
-- Abraham Lincoln
next prev parent reply other threads:[~2017-10-19 8:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-18 22:21 s2hms Emanuel Berg
2017-10-19 8:49 ` Marc Chantreux [this message]
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=20171019084938.GA11689@aurora-borealis.phear.org \
--to=khatar@phear.org \
--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).