unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Herman@debbugs.gnu.org
Cc: Géza <geza.herman@gmail.com>, 70322@debbugs.gnu.org
Subject: bug#70322: 30.0.50; format-seconds with %z doesn't handle zero input correctly
Date: Wed, 10 Apr 2024 13:23:00 +0200	[thread overview]
Message-ID: <875xwpjwbv.fsf@gmx.net> (raw)
In-Reply-To: <87v84pa67l.fsf@gmail.com> (Herman@debbugs.gnu.org's message of "Wed, 10 Apr 2024 11:59:42 +0200")

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

On Wed, 10 Apr 2024 11:59:42 +0200 Herman@debbugs.gnu.org, Géza <geza.herman@gmail.com> wrote:

> When the input seconds is 0, format-seconds emits the full string. For
> example,
>
> (format-seconds "%Y, %D, %H, %M, %z%S" 0)
>
> returns "0 years, 0 days, 0 hours, 0 minutes, 0 seconds"
>
> instead of "0 seconds".
>
> (format-seconds "%Y, %D, %H, %M, %z%S" 1) correctly returns "1 second".

The attached patch seems to fix this.

Steve Berman


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: format-seconds patch --]
[-- Type: text/x-patch, Size: 1014 bytes --]

diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index e96e2e7e2db..59e236ce3c5 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -352,9 +352,13 @@ format-seconds
           ;; Cf article-make-date-line in gnus-art.
           (setq num (floor seconds unit)
                 seconds (- seconds (* num unit)))
-          (let ((is-zero (zerop (if (= unit 1)
-                                    (+ num fraction)
-                                  num))))
+          (let ((is-zero (if (and (zerop seconds) (= unit 1))
+                             ;; Also drop leading units when SECONDS is
+                             ;; 0 (bug#70322).
+                             nil
+                           (zerop (if (= unit 1)
+                                      (+ num fraction)
+                                    num)))))
             ;; Start position of the first non-zero unit.
             (when (and (not leading-zeropos)
                        (not is-zero))

  reply	other threads:[~2024-04-10 11:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10  9:59 bug#70322: 30.0.50; format-seconds with %z doesn't handle zero input correctly Herman, Géza
2024-04-10 11:23 ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-04-10 11:58 ` Eli Zaretskii
2024-04-10 12:44   ` Herman, Géza
2024-04-10 13:00     ` Eli Zaretskii
2024-04-10 13:21       ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-10 14:01         ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=875xwpjwbv.fsf@gmx.net \
    --to=bug-gnu-emacs@gnu.org \
    --cc=70322@debbugs.gnu.org \
    --cc=Herman@debbugs.gnu.org \
    --cc=geza.herman@gmail.com \
    --cc=stephen.berman@gmx.net \
    /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.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).