]> git.eshelyaron.com Git - emacs.git/commitdiff
time-stamp: fix minor bug when parsing option combos
authorStephen Gildea <stepheng+emacs@gildea.com>
Sun, 30 May 2021 18:05:42 +0000 (11:05 -0700)
committerStephen Gildea <stepheng+emacs@gildea.com>
Sun, 30 May 2021 18:05:42 +0000 (11:05 -0700)
* lisp/time-stamp.el (time-stamp-string-preprocess): Handle digit
options correctly to avoid overcounting colon options.

* test/lisp/time-stamp-tests.el (time-stamp-format-time-zone-offset):
Add a new test case that would have caught the option-parsing error.

lisp/time-stamp.el
test/lisp/time-stamp-tests.el

index 42455ddfe33f8a3e1b0fc75d4e11fdc085e76952..0cc566f0d8cdc6c2e096ac9eb7cef46511a57077 100644 (file)
@@ -499,7 +499,8 @@ and all `time-stamp-format' compatibility."
                                (< ind fmt-len)))
                         (if (and (<= ?0 cur-char) (>= ?9 cur-char))
                             ;; get format width
-                            (let ((field-index ind))
+                            (let ((field-index ind)
+                                  (first-digit cur-char))
                               (while (progn
                                        (setq ind (1+ ind))
                                        (setq cur-char (if (< ind fmt-len)
@@ -510,6 +511,7 @@ and all `time-stamp-format' compatibility."
                               (setq field-width
                                     (substring format field-index ind))
                               (setq ind (1- ind))
+                              (setq cur-char first-digit)
                               t))))
              (setq prev-char cur-char)
              ;; some characters we actually use
index c0213536303d8eaaf4e2e2d3a9ecdd4e8c0205f7..b42271e4e51ec66825bf30f322f9499ecb0462c6 100644 (file)
       (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr)))))
 
 (ert-deftest time-stamp-format-time-zone-offset ()
-  "Test time-stamp format %z."
+  "Tests time-stamp legacy format %z and new offset format %5z."
   (with-time-stamp-test-env
     (let ((utc-abbr (format-time-string "%#Z" ref-time1 t)))
     ;; documented 1995-2019, warned since 2019, will change
     (should (equal (time-stamp-string "%_z" ref-time1) "+0000"))
     (should (equal (time-stamp-string "%:z" ref-time1) "+00:00"))
     (should (equal (time-stamp-string "%::z" ref-time1) "+00:00:00"))
+    (should (equal (time-stamp-string "%9::z" ref-time1) "+00:00:00"))
     (should (equal (time-stamp-string "%:::z" ref-time1) "+00"))))
 
 (ert-deftest time-stamp-format-non-date-conversions ()