]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix 'format-seconds' when all values are zero and %z is used
authorEli Zaretskii <eliz@gnu.org>
Wed, 10 Apr 2024 14:00:34 +0000 (17:00 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 10 Apr 2024 20:30:48 +0000 (22:30 +0200)
* lisp/calendar/time-date.el (format-seconds): Fix all-zero time.

* test/lisp/calendar/time-date-tests.el (test-format-seconds): Add
two new tests.  (Bug#70322)

(cherry picked from commit 33516970808a6c50709325edfc1af125c2b2c401)

lisp/calendar/time-date.el
test/lisp/calendar/time-date-tests.el

index e96e2e7e2db7b049363f2330c7465321d607e60d..eca80f1e8b6dcf4bd47a7cfaaf643dfbcf970157 100644 (file)
@@ -344,8 +344,11 @@ right of \"%x\", trailing zero units are not output."
              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 spec is zero, get past "%z" to last 0.
+                  (+ 2 (match-beginning 0)))))
          ((string-equal spec "x")
           (setq chop-trailing t))
          (t
index 01f9f8a5108dd099372a66b60d86b05da2a5bd92..6512dd0bd07fd648075d3ae1e6f16cd48e7ce3e7 100644 (file)
   (should (equal (format-seconds "%hh %z%x%mm %ss" (* 60 2)) "2m"))
   (should (equal (format-seconds "%hh %z%mm %ss" (* 60 2)) "2m 0s"))
   (should (equal (format-seconds "%hh %x%mm %ss" (* 60 2)) "0h 2m"))
-  (should (equal (format-seconds "%hh %x%mm %ss" 0) "0h 0m 0s")))
+  (should (equal (format-seconds "%hh %x%mm %ss" 0) "0h 0m 0s"))
+  ;; Bug#70322
+  (should (equal (format-seconds "%y %z%d %h %m %s %%" 9999999) "115 17 46 39 %"))
+  (should (equal (format-seconds "%Y, %D, %H, %M, %z%S" 0) "0 seconds")))
 
 (ert-deftest test-ordinal ()
   (should (equal (date-ordinal-to-time 2008 271)