zsh-users
 help / color / mirror / code / Atom feed
From: Emanuel Berg <moasen@zoho.com>
To: zsh-users@zsh.org
Subject: Re: s2hms
Date: Thu, 19 Oct 2017 15:03:01 +0200	[thread overview]
Message-ID: <86r2tzz3wa.fsf@zoho.com> (raw)
In-Reply-To: <20171019084938.GA11689@aurora-borealis.phear.org>

Marc Chantreux wrote:

> you don't need the $data buffer as you can
> read directly in varibles. my (untested)
> version should be more like

local secs=${1?duration in seconds} it= out=

unknown file attribute

Also, what's with the strange chars: \240 two times?

> 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
> }

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


  reply	other threads:[~2017-10-19 13:03 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 ` s2hms Marc Chantreux
2017-10-19 13:03   ` Emanuel Berg [this message]
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=86r2tzz3wa.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).