unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70322: 30.0.50; format-seconds with %z doesn't handle zero input correctly
@ 2024-04-10  9:59 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
  0 siblings, 2 replies; 7+ messages in thread
From: Herman, Géza @ 2024-04-10  9:59 UTC (permalink / raw)
  To: 70322


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".



In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, cairo version
 1.18.0) of 2024-03-23 built on okoska
Repository revision: c552cb98ad4ffbec91db52cde71cf3e0fa76e0dc
Repository branch: my-modifications
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: Debian GNU/Linux trixie/sid

Configured using:
 'configure --with-native-compilation --without-compress-install
 --without-gconf --without-gsettings --without-dbus --with-small-ja-dic
 --with-json --with-xinput2 --with-x-toolkit=no --with-tree-sitter
 --with-cairo --with-cairo-xcb --disable-silent-rules
 'CFLAGS=-mtune=native -march=native -g3 -O3''

Configured features:
ACL CAIRO FREETYPE GIF GLIB GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBOTF
LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY
INOTIFY OLDXMENU PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM ZLIB

Important settings:
  value of $LC_ALL: C.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=none
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  vertico-multiform-mode: t
  recentf-mode: t
  which-key-mode: t
  global-auto-revert-mode: t
  savehist-mode: t
  ws-butler-global-mode: t
  ws-butler-mode: t
  diff-hl-flydiff-mode: t
  global-diff-hl-mode: t
  clean-aindent-mode: t
  global-whitespace-mode: t
  marginalia-mode: t
  vertico-mode: t
  global-anzu-mode: t
  anzu-mode: t
  global-evil-matchit-mode: t
  evil-matchit-mode: t
  evil-snipe-override-mode: t
  evil-snipe-mode: t
  evil-snipe-override-local-mode: t
  evil-snipe-local-mode: t
  global-evil-surround-mode: t
  evil-surround-mode: t
  global-evil-visualstar-mode: t
  evil-visualstar-mode: t
  better-jumper-mode: t
  better-jumper-local-mode: t
  evil-leader-mode: t
  global-evil-leader-mode: t
  global-hl-todo-mode: t
  winum-mode: t
  hes-mode: t
  gcmh-mode: t
  global-page-break-lines-mode: t
  evil-mode: t
  evil-local-mode: t
  save-place-mode: t
  override-global-mode: t
  minibuffer-depth-indicate-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-history-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  abbrev-mode: t

Load-path shadows:
/home/geza/.emacs.d/elpa/transient-20240226.2332/transient hides /usr/local/share/emacs/30.0.50/lisp/transient
~/.emacs.d/lisp/emacs-gdb/gdb-mi hides /usr/local/share/emacs/30.0.50/lisp/progmodes/gdb-mi

Features:
(shadow sort project mail-extr emacsbug message mailcap yank-media puny
evil-collection-dired dired-git-info peep-dired dired-narrow delsel
dired-filter f s dired-aux dired-x dired-subtree dired-hacks-utils
evil-collection-wdired wdired ls-lisp dired dired-loaddefs rfc822 mml
mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util
time-date mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mail-utils mule-util cursor-sensor evil-collection-consult
consult-dir vertico-multiform consult-compile compile
evil-collection-comint comint ansi-osc ansi-color recentf tree-widget
wid-edit shut-up consult bookmark text-property-search pp face-remap
drag-stuff which-key autorevert filenotify savehist bm
evil-collection-info info ws-butler diff-hl-flydiff diff diff-hl
log-view pcvs-util vc-dir ewoc vc vc-dispatcher diff-mode
clean-aindent-mode column-enforce-mode whitespace orderless marginalia
vertico anzu evil-matchit evil-matchit-evil-setup evil-matchit-sdk
semantic/lex semantic/fw eieio eieio-core mode-local find-func
evil-exchange evil-args evil-indent-plus evil-textobj-line
evil-textobj-entire evil-textobj-column evil-textobj-anyblock evil-snipe
evil-surround evil-mc evil-mc-command-execute evil-mc-command-record
evil-mc-cursor-make evil-mc-region evil-mc-cursor-state evil-mc-undo
evil-mc-vars evil-mc-known-commands evil-mc-common avy evil-visualstar
evil-collection-simple evil-collection-replace evil-collection annalist
better-jumper pcase cl-macs evil-leader hl-todo compat hl-line
transpose-frame winum dash ov highlight-escape-sequences gcmh
page-break-lines evil evil-integration evil-maps evil-commands reveal
evil-jumps evil-command-window evil-types evil-search evil-ex
evil-macros evil-repeat evil-states evil-core evil-common thingatpt rect
evil-vars ring edmacro kmacro byte-opt saveplace bind-key easy-mmode
advice mb-depth comp cl-seq comp-cstr cl-extra help-mode warnings icons
subr-x gv cl-loaddefs cl-lib comp-run bytecomp byte-compile comp-common
rx rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads inotify lcms2 dynamic-setting font-render-setting cairo xinput2
x multi-tty move-toolbar make-network-process native-compile emacs)

Memory information:
((conses 16 267620 317533) (symbols 48 22835 189) (strings 32 73149 28252) (string-bytes 1 3065253) (vectors 16 36191)
 (vector-slots 8 422531 144718) (floats 8 230 208) (intervals 56 1888 275) (buffers 984 12))





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#70322: 30.0.50; format-seconds with %z doesn't handle zero input correctly
  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
  1 sibling, 0 replies; 7+ messages in thread
From: Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-10 11:23 UTC (permalink / raw)
  To: Herman; +Cc: Géza, 70322

[-- 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))

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#70322: 30.0.50; format-seconds with %z doesn't handle zero input correctly
  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
  2024-04-10 12:44   ` Herman, Géza
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2024-04-10 11:58 UTC (permalink / raw)
  To: Herman Géza; +Cc: 70322

> 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





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#70322: 30.0.50; format-seconds with %z doesn't handle zero input correctly
  2024-04-10 11:58 ` Eli Zaretskii
@ 2024-04-10 12:44   ` Herman, Géza
  2024-04-10 13:00     ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Herman, Géza @ 2024-04-10 12:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Herman Géza, 70322


Eli Zaretskii <eliz@gnu.org> writes:

> Does the patch below give good results?

Yes, both yours and Stephen's patch fix the problem





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#70322: 30.0.50; format-seconds with %z doesn't handle zero input correctly
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2024-04-10 13:00 UTC (permalink / raw)
  To: Géza Herman, Stephen Berman; +Cc: 70322

> From: Herman, Géza <geza.herman@gmail.com>
> Cc: Herman Géza <geza.herman@gmail.com>,
>  70322@debbugs.gnu.org
> Date: Wed, 10 Apr 2024 14:44:52 +0200
> 
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Does the patch below give good results?
> 
> Yes, both yours and Stephen's patch fix the problem

Thanks.

Stephen, any argumentation for which one is better?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#70322: 30.0.50; format-seconds with %z doesn't handle zero input correctly
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-10 13:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Géza Herman, 70322

On Wed, 10 Apr 2024 16:00:30 +0300 Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Herman, Géza <geza.herman@gmail.com>
>> Cc: Herman Géza <geza.herman@gmail.com>,
>>  70322@debbugs.gnu.org
>> Date: Wed, 10 Apr 2024 14:44:52 +0200
>> 
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> > Does the patch below give good results?
>> 
>> Yes, both yours and Stephen's patch fix the problem
>
> Thanks.
>
> Stephen, any argumentation for which one is better?

AFAICT both give the same results, but since yours specifically targets
the case where %z is used, which directly addresses the bug report, it
is conceptually the better fix.

Steve Berman





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#70322: 30.0.50; format-seconds with %z doesn't handle zero input correctly
  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
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2024-04-10 14:01 UTC (permalink / raw)
  To: Stephen Berman; +Cc: 70322-done, geza.herman

> From: Stephen Berman <stephen.berman@gmx.net>
> Cc: Géza Herman <geza.herman@gmail.com>,
>   70322@debbugs.gnu.org
> Date: Wed, 10 Apr 2024 15:21:59 +0200
> 
> On Wed, 10 Apr 2024 16:00:30 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
> 
> >> From: Herman, Géza <geza.herman@gmail.com>
> >> Cc: Herman Géza <geza.herman@gmail.com>,
> >>  70322@debbugs.gnu.org
> >> Date: Wed, 10 Apr 2024 14:44:52 +0200
> >> 
> >> 
> >> Eli Zaretskii <eliz@gnu.org> writes:
> >> 
> >> > Does the patch below give good results?
> >> 
> >> Yes, both yours and Stephen's patch fix the problem
> >
> > Thanks.
> >
> > Stephen, any argumentation for which one is better?
> 
> AFAICT both give the same results, but since yours specifically targets
> the case where %z is used, which directly addresses the bug report, it
> is conceptually the better fix.

Thanks, so I've now installed my change, and I'm closing this bug.





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-10 14:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).