diff options
| -rw-r--r-- | lisp/time-stamp.el | 11 | ||||
| -rw-r--r-- | test/lisp/time-stamp-tests.el | 8 |
2 files changed, 12 insertions, 7 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el index 4fb28b2fd37..284dd48d4fc 100644 --- a/lisp/time-stamp.el +++ b/lisp/time-stamp.el | |||
| @@ -545,7 +545,11 @@ and all `time-stamp-format' compatibility." | |||
| 545 | ((eq cur-char ?y) ;year | 545 | ((eq cur-char ?y) ;year |
| 546 | (if alt-form | 546 | (if alt-form |
| 547 | (string-to-number (time-stamp--format "%Y" time)) | 547 | (string-to-number (time-stamp--format "%Y" time)) |
| 548 | (string-to-number (time-stamp--format "%y" time)))) | 548 | (if (or (string-equal field-width "") |
| 549 | (<= (string-to-number field-width) 2)) | ||
| 550 | (string-to-number (time-stamp--format "%y" time)) | ||
| 551 | (time-stamp-conv-warn (format "%%%sy" field-width) "%Y") | ||
| 552 | (string-to-number (time-stamp--format "%Y" time))))) | ||
| 549 | ((eq cur-char ?Y) ;4-digit year | 553 | ((eq cur-char ?Y) ;4-digit year |
| 550 | (string-to-number (time-stamp--format "%Y" time))) | 554 | (string-to-number (time-stamp--format "%Y" time))) |
| 551 | ((eq cur-char ?z) ;time zone lower case | 555 | ((eq cur-char ?z) ;time zone lower case |
| @@ -630,8 +634,7 @@ The new forms being recommended now will continue to work then.") | |||
| 630 | 634 | ||
| 631 | (defun time-stamp-conv-warn (old-form new-form) | 635 | (defun time-stamp-conv-warn (old-form new-form) |
| 632 | "Display a warning about a soon-to-be-obsolete format. | 636 | "Display a warning about a soon-to-be-obsolete format. |
| 633 | Suggests replacing OLD-FORM with NEW-FORM. | 637 | Suggests replacing OLD-FORM with NEW-FORM." |
| 634 | In use before 2019 changes; will be used again after those changes settle." | ||
| 635 | (cond | 638 | (cond |
| 636 | (time-stamp-conversion-warn | 639 | (time-stamp-conversion-warn |
| 637 | (with-current-buffer (get-buffer-create "*Time-stamp-compatibility*") | 640 | (with-current-buffer (get-buffer-create "*Time-stamp-compatibility*") |
| @@ -640,7 +643,7 @@ In use before 2019 changes; will be used again after those changes settle." | |||
| 640 | (progn | 643 | (progn |
| 641 | (insert | 644 | (insert |
| 642 | "The formats recognized in time-stamp-format will change in a future release\n" | 645 | "The formats recognized in time-stamp-format will change in a future release\n" |
| 643 | "to be compatible with the new, expanded format-time-string function.\n\n" | 646 | "to be more compatible with the format-time-string function.\n\n" |
| 644 | "The following obsolescent time-stamp-format construct(s) were found:\n\n"))) | 647 | "The following obsolescent time-stamp-format construct(s) were found:\n\n"))) |
| 645 | (insert "\"" old-form "\" -- use " new-form "\n")) | 648 | (insert "\"" old-form "\" -- use " new-form "\n")) |
| 646 | (display-buffer "*Time-stamp-compatibility*")))) | 649 | (display-buffer "*Time-stamp-compatibility*")))) |
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el index 287b5f486c3..ace5e58e367 100644 --- a/test/lisp/time-stamp-tests.el +++ b/test/lisp/time-stamp-tests.el | |||
| @@ -46,8 +46,7 @@ | |||
| 46 | (put 'with-time-stamp-test-env 'lisp-indent-hook 'defun) | 46 | (put 'with-time-stamp-test-env 'lisp-indent-hook 'defun) |
| 47 | 47 | ||
| 48 | (defmacro time-stamp-should-warn (form) | 48 | (defmacro time-stamp-should-warn (form) |
| 49 | "Similar to `should' but verifies that a format warning is generated. | 49 | "Similar to `should' but verifies that a format warning is generated." |
| 50 | In use before 2019 changes; will be used again after those changes settle." | ||
| 51 | `(let ((warning-count 0)) | 50 | `(let ((warning-count 0)) |
| 52 | (cl-letf (((symbol-function 'time-stamp-conv-warn) | 51 | (cl-letf (((symbol-function 'time-stamp-conv-warn) |
| 53 | (lambda (_old _new) | 52 | (lambda (_old _new) |
| @@ -266,7 +265,10 @@ In use before 2019 changes; will be used again after those changes settle." | |||
| 266 | (should (equal (time-stamp-string "%_y" ref-time) " 6")) | 265 | (should (equal (time-stamp-string "%_y" ref-time) " 6")) |
| 267 | (should (equal (time-stamp-string "%_y" ref-time2) "16")) | 266 | (should (equal (time-stamp-string "%_y" ref-time2) "16")) |
| 268 | (should (equal (time-stamp-string "%y" ref-time) "06")) | 267 | (should (equal (time-stamp-string "%y" ref-time) "06")) |
| 269 | (should (equal (time-stamp-string "%y" ref-time2) "16")))) | 268 | (should (equal (time-stamp-string "%y" ref-time2) "16")) |
| 269 | ;; implemented since 1995, warned since 2019, will change | ||
| 270 | (time-stamp-should-warn (equal (time-stamp-string "%04y" ref-time) "2006")) | ||
| 271 | (time-stamp-should-warn (equal (time-stamp-string "%4y" ref-time) "2006")))) | ||
| 270 | 272 | ||
| 271 | (ert-deftest time-stamp-test-year-4digit () | 273 | (ert-deftest time-stamp-test-year-4digit () |
| 272 | "Test time-stamp format %Y." | 274 | "Test time-stamp format %Y." |