aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Gildea2021-05-30 11:05:42 -0700
committerStephen Gildea2021-05-30 11:05:42 -0700
commita5b57fc6af7ec87c59d00a7631576f9f4bf99841 (patch)
tree2384eb75571f6a069938889362b2307dfd5f7350
parentd6dc66053d846b6fc041889b4d0f383c8dac4da3 (diff)
downloademacs-a5b57fc6af7ec87c59d00a7631576f9f4bf99841.tar.gz
emacs-a5b57fc6af7ec87c59d00a7631576f9f4bf99841.zip
time-stamp: fix minor bug when parsing option combos
* 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.
-rw-r--r--lisp/time-stamp.el4
-rw-r--r--test/lisp/time-stamp-tests.el3
2 files changed, 5 insertions, 2 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el
index 42455ddfe33..0cc566f0d8c 100644
--- a/lisp/time-stamp.el
+++ b/lisp/time-stamp.el
@@ -499,7 +499,8 @@ and all `time-stamp-format' compatibility."
499 (< ind fmt-len))) 499 (< ind fmt-len)))
500 (if (and (<= ?0 cur-char) (>= ?9 cur-char)) 500 (if (and (<= ?0 cur-char) (>= ?9 cur-char))
501 ;; get format width 501 ;; get format width
502 (let ((field-index ind)) 502 (let ((field-index ind)
503 (first-digit cur-char))
503 (while (progn 504 (while (progn
504 (setq ind (1+ ind)) 505 (setq ind (1+ ind))
505 (setq cur-char (if (< ind fmt-len) 506 (setq cur-char (if (< ind fmt-len)
@@ -510,6 +511,7 @@ and all `time-stamp-format' compatibility."
510 (setq field-width 511 (setq field-width
511 (substring format field-index ind)) 512 (substring format field-index ind))
512 (setq ind (1- ind)) 513 (setq ind (1- ind))
514 (setq cur-char first-digit)
513 t)))) 515 t))))
514 (setq prev-char cur-char) 516 (setq prev-char cur-char)
515 ;; some characters we actually use 517 ;; some characters we actually use
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el
index c0213536303..b42271e4e51 100644
--- a/test/lisp/time-stamp-tests.el
+++ b/test/lisp/time-stamp-tests.el
@@ -525,7 +525,7 @@
525 (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr))))) 525 (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr)))))
526 526
527(ert-deftest time-stamp-format-time-zone-offset () 527(ert-deftest time-stamp-format-time-zone-offset ()
528 "Test time-stamp format %z." 528 "Tests time-stamp legacy format %z and new offset format %5z."
529 (with-time-stamp-test-env 529 (with-time-stamp-test-env
530 (let ((utc-abbr (format-time-string "%#Z" ref-time1 t))) 530 (let ((utc-abbr (format-time-string "%#Z" ref-time1 t)))
531 ;; documented 1995-2019, warned since 2019, will change 531 ;; documented 1995-2019, warned since 2019, will change
@@ -544,6 +544,7 @@
544 (should (equal (time-stamp-string "%_z" ref-time1) "+0000")) 544 (should (equal (time-stamp-string "%_z" ref-time1) "+0000"))
545 (should (equal (time-stamp-string "%:z" ref-time1) "+00:00")) 545 (should (equal (time-stamp-string "%:z" ref-time1) "+00:00"))
546 (should (equal (time-stamp-string "%::z" ref-time1) "+00:00:00")) 546 (should (equal (time-stamp-string "%::z" ref-time1) "+00:00:00"))
547 (should (equal (time-stamp-string "%9::z" ref-time1) "+00:00:00"))
547 (should (equal (time-stamp-string "%:::z" ref-time1) "+00")))) 548 (should (equal (time-stamp-string "%:::z" ref-time1) "+00"))))
548 549
549(ert-deftest time-stamp-format-non-date-conversions () 550(ert-deftest time-stamp-format-non-date-conversions ()