1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

time-stamp: minor adjustments to %P and modifier characters

* lisp/time-stamp.el (time-stamp-string-preprocess): %P variations;
allow (and ignore) "*", "E", and "O" as modifier characters.
(time-stamp-inserts-lines): safe-local-variable only if booleanp
This commit is contained in:
Stephen Gildea 2024-11-08 10:42:30 -08:00
parent 551d1a2cd7
commit 766ec1f9e0
2 changed files with 40 additions and 17 deletions

View File

@ -223,7 +223,7 @@ for generating repeated time stamps.
These variables are best changed with file-local variables.
If you were to change `time-stamp-end' or `time-stamp-inserts-lines' in
your init file, you would be incompatible with other people's files.")
;;;###autoload(put 'time-stamp-inserts-lines 'safe-local-variable 'symbolp)
;;;###autoload(put 'time-stamp-inserts-lines 'safe-local-variable 'booleanp)
(defvar time-stamp-count 1 ;Do not change!
@ -519,7 +519,8 @@ and all `time-stamp-format' compatibility."
(setq cur-char (if (< ind fmt-len)
(aref format ind)
?\0))
(or (eq ?. cur-char)
(or (eq ?. cur-char) (eq ?* cur-char)
(eq ?E cur-char) (eq ?O cur-char)
(eq ?, cur-char) (eq ?: cur-char) (eq ?@ cur-char)
(eq ?- cur-char) (eq ?+ cur-char) (eq ?_ cur-char)
(eq ?\s cur-char) (eq ?# cur-char) (eq ?^ cur-char)
@ -602,12 +603,18 @@ and all `time-stamp-format' compatibility."
(time-stamp-do-number cur-char alt-form field-width time))
((eq cur-char ?M) ;minute, 0-59
(time-stamp-do-number cur-char alt-form field-width time))
((eq cur-char ?p) ;am or pm
((eq cur-char ?p) ;AM or PM
(if change-case
(time-stamp--format "%#p" time)
(time-stamp--format "%p" time)))
(if upcase
(time-stamp--format "%^p" time)
(time-stamp--format "%p" time))))
((eq cur-char ?P) ;AM or PM
(time-stamp--format "%p" time))
(if change-case
(time-stamp--format "%#p" time)
(if upcase
"" ;discourage inconsistent "%^P"
(time-stamp--format "%p" time))))
((eq cur-char ?S) ;seconds, 00-60
(time-stamp-do-number cur-char alt-form field-width time))
((eq cur-char ?w) ;weekday number, Sunday is 0

View File

@ -504,18 +504,32 @@
(ert-deftest time-stamp-format-am-pm ()
"Test time-stamp formats for AM and PM strings."
(with-time-stamp-test-env
(let ((pm (format-time-string "%#p" ref-time1 t))
(am (format-time-string "%#p" ref-time3 t))
(PM (format-time-string "%p" ref-time1 t))
(AM (format-time-string "%p" ref-time3 t)))
(let ((pm (format-time-string "%P" ref-time1 t))
(am (format-time-string "%P" ref-time3 t))
(Pm (format-time-string "%p" ref-time1 t))
(Am (format-time-string "%p" ref-time3 t))
(PM (format-time-string "%^p" ref-time1 t))
(AM (format-time-string "%^p" ref-time3 t)))
;; implemented and documented since 1997
(should (equal (time-stamp-string "%#p" ref-time1) pm))
(should (equal (time-stamp-string "%#p" ref-time3) am))
(should (equal (time-stamp-string "%P" ref-time1) PM))
(should (equal (time-stamp-string "%P" ref-time3) AM))
(should (equal (time-stamp-string "%P" ref-time1) Pm))
(should (equal (time-stamp-string "%P" ref-time3) Am))
;; implemented since 1997
(should (equal (time-stamp-string "%^#p" ref-time1) pm))
(should (equal (time-stamp-string "%^#p" ref-time3) am))
;; warned 1997-2019, changed in 2019
(should (equal (time-stamp-string "%p" ref-time1) PM))
(should (equal (time-stamp-string "%p" ref-time3) AM)))))
(should (equal (time-stamp-string "%p" ref-time1) Pm))
(should (equal (time-stamp-string "%p" ref-time3) Am))
;; changed in 2024
(should (equal (time-stamp-string "%^p" ref-time1) PM))
(should (equal (time-stamp-string "%^p" ref-time3) AM))
(should (equal (time-stamp-string "%#P" ref-time1) pm))
(should (equal (time-stamp-string "%#P" ref-time3) am))
(should (equal (time-stamp-string "%^#P" ref-time1) pm))
(should (equal (time-stamp-string "%^#P" ref-time3) am))
(should (equal (time-stamp-string "%^P" ref-time1) ""))
(should (equal (time-stamp-string "%^P" ref-time3) "")))))
(ert-deftest time-stamp-format-day-number-in-week ()
"Test time-stamp formats for day number in week."
@ -596,7 +610,7 @@
(with-time-stamp-test-env
(let ((May (format-time-string "%B" ref-time3 t)))
;; allowed modifiers
(should (equal (time-stamp-string "%.,@+ (stuff)B" ref-time3) May))
(should (equal (time-stamp-string "%.,@+*EO (stuff)B" ref-time3) May))
;; parens nest
(should (equal (time-stamp-string "%(st(u)ff)B" ref-time3) May))
;; escaped parens do not change the nesting level
@ -703,7 +717,7 @@
(should-not (safe-local-variable-p 'time-stamp-format '(a list)))
(should (safe-local-variable-p 'time-stamp-time-zone "a string"))
(should-not (safe-local-variable-p 'time-stamp-time-zone 0.5))
(should (safe-local-variable-p 'time-stamp-line-limit 8))
(should (safe-local-variable-p 'time-stamp-line-limit -10))
(should-not (safe-local-variable-p 'time-stamp-line-limit "a string"))
(should (safe-local-variable-p 'time-stamp-start "a string"))
(should-not (safe-local-variable-p 'time-stamp-start 17))
@ -961,6 +975,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
("+000030" formatz-mod-del-colons)
("+100:00")
("+100:00:30"))
;; Tests that minus with padding pads with spaces.
(formatz-generate-tests ("%-12z")
("+00 " formatz-mod-pad-r12)
@ -968,6 +983,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
("+000030 " formatz-mod-del-colons formatz-mod-pad-r12)
("+100:00 " formatz-mod-pad-r12)
("+100:00:30 " formatz-mod-pad-r12))
;; Tests that 0 after other digits becomes padding of ten, not zero flag.
(formatz-generate-tests ("%-10z")
("+00 " formatz-mod-pad-r10)