Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] ztrftime(): Fix truncation for %.
- X-seq: zsh-workers 43937
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: dana <dana@xxxxxxx>, Zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH] ztrftime(): Fix truncation for %.
- Date: Mon, 24 Dec 2018 12:45:45 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:references:in-reply-to :date:subject; s=fm2; bh=JkS9XHVEzUnVT9bGzo2uR//6ZfZeXTzs6kUCfwe gaPw=; b=cOQQXGNn9YjC/09Tdatz3IE9dq6xpPIzaoXkxnULoEzYV1pQ92T7FuK u/u7mkNeeCak0Q/dp5xcoivx0xFlBIhn/hGBgL7sxoYm5aEJbb6lgrx+1y0Mrk6J jDnx+vjbomTmTEkUBLyiJUC/T9acJ4y7ZfBfv2MbKFuYjq/+2MYSt7nVUOLD8Ooz AW3IuRSfBZFxlFfPYr5wfwWhp3skCCV2kODvNr7OY+UZzVyf9UCgWhDmXal1xgFS 9xeCkV3jkunUZErlB9KPVEF2w1rwMGuIadx2v+YGudKYzml3RhtDKK6puQAUijKF EWSgWvLERMQUyJ4Jbs8/w8ANlTy1s7g==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=JkS9XHVEzUnVT9bGzo2uR//6ZfZeXTzs6kUCfwega Pw=; b=HEgGHwy/QEhFY8k0dNpGAjfF/2sGDc++CNsrAt3LQVxltQj1FcvxgfeZR nAuZXKzyTCcXT5sXvIJ++6wIYipb+BD0W1e3t58IDtKOp1aPt5v5DvoOB1RAnqGP XaRBrFROoDqO3/FsTJfPIbEqAKr5/c8yU/LB71IUf1ENcCCEuKMJadhVXxTBFhzs 9UsKaext5MjP3ubuq2FNphVmA4SfX6X+vyxqFbbHA5h4uoHnQOzEqzJlIhk5q0yV YLTmBHE0SwVHI3H5fBwtAZmWc0AfMWD2OisPppxB7YpFOASZyrxF/mEY0zpResPr R6zkGBADKXJXm1lphypwKL0DXoCNw==
- In-reply-to: <C910A9B2-EFC0-49CC-B980-38127CC81175@dana.is>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <d7b0451f90bdfe61f48cc1361690180e07158900.camel@ntlworld.com> <20181224054021.GK1941@sym.noone.org> <20181224071421.GL1941@sym.noone.org> <C7926210-86FE-4626-9A93-4A387C315CC4@dana.is> <C910A9B2-EFC0-49CC-B980-38127CC81175@dana.is>
dana wrote on Mon, 24 Dec 2018 03:16 -0600:
> Not directly related, but in reviewing workers/43932 further i found that the
> way ztrftime() handles truncation for %. is problematic:
>
> % strftime '%s.%9.' $EPOCHSECONDS $(( 999_999_999 ))
> 1545638724.999999999
> % strftime '%s.%6.' $EPOCHSECONDS $(( 999_999_000 ))
> 1545638984.999999
> % strftime '%s.%6.' $EPOCHSECONDS $(( 999_999_999 ))
> 1545638724.100000
That's a very odd sequence of $EPOCHSECONDS values. :P
Also, in (unpatched) master:
% strftime '[%3.]' 123456789
[000]
% strftime '[%s][%3.]' 0 123456789
[0][124]
%
Shouldn't the former print [124]?
> I'm not very good at maths — is there a reason it shouldn't just be a straight
> power-of-ten division like this?
Using straight division likes this makes it do truncation; in the code
before this patch, the +8 makes it so nsec=11152 would print '1116'
but nsec=11151 would print '1115'. (The +8 should probably be +5 ---
half the radix.) 999999999 is an edge case since it rounds up "to the
next second".
> +++ b/Src/utils.c
> @@ -3340,9 +3340,8 @@ morefmt:
> digs = 9;
> if (digs < 9) {
> int trunc;
> - for (trunc = 8 - digs; trunc; trunc--)
> + for (trunc = 9 - digs; trunc; trunc--)
> nsec /= 10;
> - nsec = (nsec + 8) / 10;
> }
> sprintf(buf, "%0*ld", digs, nsec);
> buf += digs;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author