]> git.eshelyaron.com Git - emacs.git/commitdiff
time-stamp: minor adjustments to %P and modifier characters
authorStephen Gildea <stepheng+emacs@gildea.com>
Fri, 8 Nov 2024 18:42:30 +0000 (10:42 -0800)
committerEshel Yaron <me@eshelyaron.com>
Sat, 9 Nov 2024 15:47:51 +0000 (16:47 +0100)
* 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

(cherry picked from commit 766ec1f9e08e6f2c7c22b514a6f2e65f79341023)

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

index 1b95396e744a6f26de397a73a79adf62b595f779..a02c1d4532ddf4aa883faeddc2d44b8d483e0714 100644 (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)))
+                       (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
index 36889257724b3eade317c56d094de5f7e0feed9a..b05904ad0176961ce32772acf7508b50c200ce97 100644 (file)
 (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."
   "Test time-stamp format %Z."
   (with-time-stamp-test-env
     (let ((UTC-abbr (format-time-string "%Z" ref-time1 t))
-         (utc-abbr (format-time-string "%#Z" ref-time1 t)))
+          (utc-abbr (format-time-string "%#Z" ref-time1 t)))
       ;; implemented and documented since 1995
       (should (equal (time-stamp-string "%Z" ref-time1) UTC-abbr))
       ;; implemented since 1997, documented since 2019
   (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
   (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)