all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: "Herman Géza" <geza.herman@gmail.com>
Cc: 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 14:58:53 +0300	[thread overview]
Message-ID: <861q7dwhs2.fsf@gnu.org> (raw)
In-Reply-To: <87v84pa67l.fsf@gmail.com> (Herman@debbugs.gnu.org)

> From: Herman@debbugs.gnu.org, Géza <geza.herman@gmail.com>
> Date: Wed, 10 Apr 2024 11:59:42 +0200
> 
> 
> 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".

Does the patch below give good results?

diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index e96e2e7..b75f17c 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -344,8 +344,11 @@ format-seconds
              string)
         (cond
          ((string-equal spec "z")
-          (setq chop-leading (and leading-zeropos
-                                  (min leading-zeropos (match-beginning 0)))))
+          (setq chop-leading
+                (if leading-zeropos
+                    (min leading-zeropos (match-beginning 0))
+                  ;; The entire speci is zero, get past "%z" to last 0.
+                  (+ 2 (match-beginning 0)))))
          ((string-equal spec "x")
           (setq chop-trailing t))
          (t





  parent reply	other threads:[~2024-04-10 11:58 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
2024-04-10 11:58 ` Eli Zaretskii [this message]
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

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

  git send-email \
    --in-reply-to=861q7dwhs2.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=70322@debbugs.gnu.org \
    --cc=geza.herman@gmail.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.