diff options
| author | Stephen Gildea | 2024-11-01 09:32:27 -0700 |
|---|---|---|
| committer | Stephen Gildea | 2024-11-01 09:36:07 -0700 |
| commit | ffda8dfe847094bd8488059be2f96270fe298fa5 (patch) | |
| tree | c6b8b50aabf671b7a000fb48e543e520df2244d5 | |
| parent | 872be2bb5febc5a720d6f4dbbd2fd30561385bb6 (diff) | |
| download | emacs-ffda8dfe847094bd8488059be2f96270fe298fa5.tar.gz emacs-ffda8dfe847094bd8488059be2f96270fe298fa5.zip | |
; time-stamp: Reformat some long doc strings for clarity.
* lisp/time-stamp.el (time-stamp-format, time-stamp-pattern): Reformat
doc strings for clarity.
(group time-stamp): is a subgroup of "files", not "data".
The "data" group seems to be for editing non-text files.
* test/lisp/time-stamp-tests.el: Fix tense of some doc strings.
| -rw-r--r-- | lisp/time-stamp.el | 87 | ||||
| -rw-r--r-- | test/lisp/time-stamp-tests.el | 48 |
2 files changed, 69 insertions, 66 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el index 8c28920d219..1b95396e744 100644 --- a/lisp/time-stamp.el +++ b/lisp/time-stamp.el | |||
| @@ -5,8 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | ;; This file is part of GNU Emacs. | 6 | ;; This file is part of GNU Emacs. |
| 7 | 7 | ||
| 8 | ;; Maintainer: Stephen Gildea <stepheng+emacs@gildea.com> | 8 | ;; Author: Stephen Gildea <stepheng+emacs@gildea.com> |
| 9 | ;; Keywords: tools | 9 | ;; Keywords: files, tools |
| 10 | 10 | ||
| 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
| 12 | ;; it under the terms of the GNU General Public License as published by | 12 | ;; it under the terms of the GNU General Public License as published by |
| @@ -25,20 +25,19 @@ | |||
| 25 | 25 | ||
| 26 | ;; A template in a file can be updated with a new time stamp when | 26 | ;; A template in a file can be updated with a new time stamp when |
| 27 | ;; you save the file. For example: | 27 | ;; you save the file. For example: |
| 28 | ;; static char *ts = "sdmain.c Time-stamp: <2020-04-18 14:10:21 gildea>"; | 28 | ;; static char *ts = "sdmain.c Time-stamp: <2024-04-18 14:10:21 gildea>"; |
| 29 | 29 | ||
| 30 | ;; To use time-stamping, add this line to your init file: | 30 | ;; To use time-stamping, add this line to your init file: |
| 31 | ;; (add-hook 'before-save-hook 'time-stamp) | 31 | ;; (add-hook 'before-save-hook 'time-stamp) |
| 32 | ;; Now any time-stamp templates in your files will be updated automatically. | 32 | ;; Now any time-stamp templates in your files will be updated automatically. |
| 33 | 33 | ||
| 34 | ;; See the documentation for the functions `time-stamp' | 34 | ;; See the documentation for the function `time-stamp' for details. |
| 35 | ;; and `time-stamp-toggle-active' for details. | ||
| 36 | 35 | ||
| 37 | ;;; Code: | 36 | ;;; Code: |
| 38 | 37 | ||
| 39 | (defgroup time-stamp nil | 38 | (defgroup time-stamp nil |
| 40 | "Maintain last change time stamps in files edited by Emacs." | 39 | "Maintain last change time stamps in files edited by Emacs." |
| 41 | :group 'data | 40 | :group 'files |
| 42 | :group 'extensions) | 41 | :group 'extensions) |
| 43 | 42 | ||
| 44 | 43 | ||
| @@ -47,34 +46,34 @@ | |||
| 47 | This is a string, used verbatim except for character sequences beginning | 46 | This is a string, used verbatim except for character sequences beginning |
| 48 | with %, as follows. | 47 | with %, as follows. |
| 49 | 48 | ||
| 50 | %:A weekday name: `Monday' %#A gives uppercase: `MONDAY' | 49 | %:A weekday name: `Monday' %#A gives uppercase: `MONDAY' |
| 51 | %3a abbreviated weekday: `Mon' %#a gives uppercase: `MON' | 50 | %3a abbreviated weekday: `Mon' %#a gives uppercase: `MON' |
| 52 | %:B month name: `January' %#B gives uppercase: `JANUARY' | 51 | %:B month name: `January' %#B gives uppercase: `JANUARY' |
| 53 | %3b abbreviated month: `Jan' %#b gives uppercase: `JAN' | 52 | %3b abbreviated month: `Jan' %#b gives uppercase: `JAN' |
| 54 | %02d day of month | 53 | %02d day of month |
| 55 | %02H 24-hour clock hour | 54 | %02H 24-hour clock hour |
| 56 | %02I 12-hour clock hour | 55 | %02I 12-hour clock hour |
| 57 | %02m month number | 56 | %02m month number |
| 58 | %02M minute | 57 | %02M minute |
| 59 | %#p `am' or `pm' %P gives uppercase: `AM' or `PM' | 58 | %#p `am' or `pm' %P gives uppercase: `AM' or `PM' |
| 60 | %02S seconds | 59 | %02S seconds |
| 61 | %w day number of week, Sunday is 0 | 60 | %w day number of week, Sunday is 0 |
| 62 | %02y 2-digit year %Y 4-digit year | 61 | %02y 2-digit year %Y 4-digit year |
| 63 | %Z time zone name: `EST' %#Z gives lowercase: `est' | 62 | %Z time zone name: `EST' %#Z gives lowercase: `est' |
| 64 | %5z time zone offset: `-0500' (since Emacs 27; see note below) | 63 | %5z time zone offset: `-0500' (since Emacs 27; see note below) |
| 65 | 64 | ||
| 66 | Non-date items: | 65 | Non-date items: |
| 67 | %% a literal percent character: `%' | 66 | %% a literal percent character: `%' |
| 68 | %f file name without directory %F absolute file name | 67 | %f file name without directory %F absolute file name |
| 69 | %l login name %L full name of logged-in user | 68 | %l login name %L full name of logged-in user |
| 70 | %q unqualified host name %Q fully-qualified host name | 69 | %q unqualified host name %Q fully-qualified host name |
| 71 | %h mail host name | 70 | %h mail host name |
| 72 | 71 | ||
| 73 | Decimal digits between the % and the type character specify the | 72 | Decimal digits between the % and the type character specify the |
| 74 | field width. Strings are truncated on the right. | 73 | field width. Strings are truncated on the right. |
| 75 | A leading zero in the field width zero-fills a number. | 74 | A leading zero in the field width zero-fills a number. |
| 76 | 75 | ||
| 77 | For example, to get the format used by the `date' command, | 76 | For example, to get a common format used by the `date' command, |
| 78 | use \"%3a %3b %2d %02H:%02M:%02S %Z %Y\". | 77 | use \"%3a %3b %2d %02H:%02M:%02S %Z %Y\". |
| 79 | 78 | ||
| 80 | The values of non-numeric formatted items depend on the locale | 79 | The values of non-numeric formatted items depend on the locale |
| @@ -266,20 +265,22 @@ If you were to change `time-stamp-pattern', `time-stamp-line-limit', | |||
| 266 | `time-stamp-start', or `time-stamp-end' in your init file, you | 265 | `time-stamp-start', or `time-stamp-end' in your init file, you |
| 267 | would be incompatible with other people's files. | 266 | would be incompatible with other people's files. |
| 268 | 267 | ||
| 269 | See also `time-stamp-count' and `time-stamp-inserts-lines'. | ||
| 270 | |||
| 271 | Examples: | 268 | Examples: |
| 272 | 269 | ||
| 273 | \"-10/\" (sets only `time-stamp-line-limit') | 270 | ;; time-stamp-pattern: \"-10/\" |
| 271 | (sets only `time-stamp-line-limit') | ||
| 272 | |||
| 273 | // time-stamp-pattern: \"-9/^Last modified: %%$\" | ||
| 274 | (sets `time-stamp-line-limit', `time-stamp-start' and `time-stamp-end') | ||
| 275 | |||
| 276 | @c time-stamp-pattern: \"@set Time-stamp: %:B %1d, %Y$\" | ||
| 277 | (sets `time-stamp-start', `time-stamp-format' and `time-stamp-end') | ||
| 274 | 278 | ||
| 275 | \"-9/^Last modified: %%$\" (sets `time-stamp-line-limit', | 279 | %% time-stamp-pattern: \"newcommand{\\\\\\\\timestamp}{%%}\" |
| 276 | `time-stamp-start' and `time-stamp-end') | 280 | (sets `time-stamp-start'and `time-stamp-end') |
| 277 | 281 | ||
| 278 | \"@set Time-stamp: %:B %1d, %Y$\" (sets `time-stamp-start', | ||
| 279 | `time-stamp-format' and `time-stamp-end') | ||
| 280 | 282 | ||
| 281 | \"newcommand{\\\\\\\\timestamp}{%%}\" (sets `time-stamp-start' | 283 | See also `time-stamp-count' and `time-stamp-inserts-lines'.") |
| 282 | and `time-stamp-end')") | ||
| 283 | ;;;###autoload(put 'time-stamp-pattern 'safe-local-variable 'stringp) | 284 | ;;;###autoload(put 'time-stamp-pattern 'safe-local-variable 'stringp) |
| 284 | 285 | ||
| 285 | 286 | ||
| @@ -287,8 +288,8 @@ and `time-stamp-end')") | |||
| 287 | ;;;###autoload | 288 | ;;;###autoload |
| 288 | (defun time-stamp () | 289 | (defun time-stamp () |
| 289 | "Update any time stamp string(s) in the buffer. | 290 | "Update any time stamp string(s) in the buffer. |
| 290 | This function looks for a time stamp template and updates it with | 291 | Look for a time stamp template and update it with the current date, |
| 291 | the current date, time, and/or other info. | 292 | time, and/or other info. |
| 292 | 293 | ||
| 293 | The template, which you manually create on one of the first 8 lines | 294 | The template, which you manually create on one of the first 8 lines |
| 294 | of the file before running this function, by default can look like | 295 | of the file before running this function, by default can look like |
| @@ -297,7 +298,7 @@ one of the following (your choice): | |||
| 297 | Time-stamp: \" \" | 298 | Time-stamp: \" \" |
| 298 | This function writes the current time between the brackets or quotes, | 299 | This function writes the current time between the brackets or quotes, |
| 299 | by default formatted like this: | 300 | by default formatted like this: |
| 300 | Time-stamp: <2020-08-07 17:10:21 gildea> | 301 | Time-stamp: <2024-08-07 17:10:21 gildea> |
| 301 | 302 | ||
| 302 | Although you can run this function manually to update a time stamp | 303 | Although you can run this function manually to update a time stamp |
| 303 | once, usually you want automatic time stamp updating. | 304 | once, usually you want automatic time stamp updating. |
| @@ -311,7 +312,7 @@ To enable automatic time-stamping for only a specific file, add | |||
| 311 | this line to a local variables list near the end of the file: | 312 | this line to a local variables list near the end of the file: |
| 312 | eval: (add-hook \\='before-save-hook \\='time-stamp nil t) | 313 | eval: (add-hook \\='before-save-hook \\='time-stamp nil t) |
| 313 | 314 | ||
| 314 | If the file has no time-stamp template, this function does nothing. | 315 | If the file has no time stamp template, this function does nothing. |
| 315 | 316 | ||
| 316 | You can set `time-stamp-pattern' in a file's local variables list | 317 | You can set `time-stamp-pattern' in a file's local variables list |
| 317 | to customize the information in the time stamp and where it is written. | 318 | to customize the information in the time stamp and where it is written. |
| @@ -419,7 +420,7 @@ Returns the end point, which is where `time-stamp' begins the next search." | |||
| 419 | (cond | 420 | (cond |
| 420 | ((not time-stamp-active) | 421 | ((not time-stamp-active) |
| 421 | (if time-stamp-warn-inactive | 422 | (if time-stamp-warn-inactive |
| 422 | ;; don't signal an error in a write-file-hook | 423 | ;; don't signal an error in a hook |
| 423 | (progn | 424 | (progn |
| 424 | (message "Warning: time-stamp-active is off; did not time-stamp buffer.") | 425 | (message "Warning: time-stamp-active is off; did not time-stamp buffer.") |
| 425 | (sit-for 1)))) | 426 | (sit-for 1)))) |
| @@ -801,6 +802,8 @@ Suggests replacing OLD-FORM with NEW-FORM." | |||
| 801 | ;; - The %_z format always outputs seconds, allowing all added padding | 802 | ;; - The %_z format always outputs seconds, allowing all added padding |
| 802 | ;; to be spaces. Without this rule, there would be no way to | 803 | ;; to be spaces. Without this rule, there would be no way to |
| 803 | ;; request seconds that worked for both 2- and 3-digit hours. | 804 | ;; request seconds that worked for both 2- and 3-digit hours. |
| 805 | ;; (We consider 3-digit hours not because such offsets are in use but | ||
| 806 | ;; instead to guide our design toward consistency and extensibility.) | ||
| 804 | ;; - Conflicting options are rejected, lest users depend | 807 | ;; - Conflicting options are rejected, lest users depend |
| 805 | ;; on incidental behavior. | 808 | ;; on incidental behavior. |
| 806 | ;; | 809 | ;; |
| @@ -843,7 +846,7 @@ Suggests replacing OLD-FORM with NEW-FORM." | |||
| 843 | colon-count | 846 | colon-count |
| 844 | field-width | 847 | field-width |
| 845 | offset-secs) | 848 | offset-secs) |
| 846 | "Formats a time offset according to a %z variation. | 849 | "Format a time offset according to a %z variation. |
| 847 | 850 | ||
| 848 | With no flags, the output includes hours and minutes: +-HHMM | 851 | With no flags, the output includes hours and minutes: +-HHMM |
| 849 | unless there is a non-zero seconds part, in which case the seconds | 852 | unless there is a non-zero seconds part, in which case the seconds |
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el index a4c30d64225..36889257724 100644 --- a/test/lisp/time-stamp-tests.el +++ b/test/lisp/time-stamp-tests.el | |||
| @@ -535,7 +535,7 @@ | |||
| 535 | (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr))))) | 535 | (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr))))) |
| 536 | 536 | ||
| 537 | (ert-deftest time-stamp-format-time-zone-offset () | 537 | (ert-deftest time-stamp-format-time-zone-offset () |
| 538 | "Tests time-stamp legacy format %z and spot tests of new offset format %5z." | 538 | "Test time-stamp legacy format %z and spot-test new offset format %5z." |
| 539 | (with-time-stamp-test-env | 539 | (with-time-stamp-test-env |
| 540 | (let ((utc-abbr (format-time-string "%#Z" ref-time1 t))) | 540 | (let ((utc-abbr (format-time-string "%#Z" ref-time1 t))) |
| 541 | ;; documented 1995-2019, warned since 2019, will change | 541 | ;; documented 1995-2019, warned since 2019, will change |
| @@ -617,7 +617,7 @@ | |||
| 617 | (should (equal (time-stamp-string "No percent" ref-time1) "No percent")))) | 617 | (should (equal (time-stamp-string "No percent" ref-time1) "No percent")))) |
| 618 | 618 | ||
| 619 | (ert-deftest time-stamp-format-multiple-conversions () | 619 | (ert-deftest time-stamp-format-multiple-conversions () |
| 620 | "Tests that multiple %-conversions are independent." | 620 | "Test that multiple %-conversions are independent." |
| 621 | (with-time-stamp-test-env | 621 | (with-time-stamp-test-env |
| 622 | (let ((Mon (format-time-string "%a" ref-time1 t)) | 622 | (let ((Mon (format-time-string "%a" ref-time1 t)) |
| 623 | (MON (format-time-string "%^a" ref-time1 t)) | 623 | (MON (format-time-string "%^a" ref-time1 t)) |
| @@ -719,7 +719,7 @@ | |||
| 719 | ;;;; Setup for tests of time offset formatting with %z | 719 | ;;;; Setup for tests of time offset formatting with %z |
| 720 | 720 | ||
| 721 | (defun formatz (format zone) | 721 | (defun formatz (format zone) |
| 722 | "Uses FORMAT to format the offset of ZONE, returning the result. | 722 | "Use FORMAT to format the offset of ZONE, returning the result. |
| 723 | FORMAT must be time format \"%z\" or some variation thereof. | 723 | FORMAT must be time format \"%z\" or some variation thereof. |
| 724 | ZONE is as the ZONE argument of the `format-time-string' function. | 724 | ZONE is as the ZONE argument of the `format-time-string' function. |
| 725 | This function is called by 99% of the `time-stamp' \"%z\" unit tests." | 725 | This function is called by 99% of the `time-stamp' \"%z\" unit tests." |
| @@ -733,7 +733,7 @@ This function is called by 99% of the `time-stamp' \"%z\" unit tests." | |||
| 733 | ))) | 733 | ))) |
| 734 | 734 | ||
| 735 | (defun format-time-offset (format offset-secs) | 735 | (defun format-time-offset (format offset-secs) |
| 736 | "Uses FORMAT to format the time zone represented by OFFSET-SECS. | 736 | "Use FORMAT to format the time zone represented by OFFSET-SECS. |
| 737 | FORMAT must be time format \"%z\" or some variation thereof. | 737 | FORMAT must be time format \"%z\" or some variation thereof. |
| 738 | This function is a wrapper around `time-stamp-formatz-from-parsed-options' | 738 | This function is a wrapper around `time-stamp-formatz-from-parsed-options' |
| 739 | and is called by some low-level `time-stamp' \"%z\" unit tests." | 739 | and is called by some low-level `time-stamp' \"%z\" unit tests." |
| @@ -765,20 +765,20 @@ and is called by some low-level `time-stamp' \"%z\" unit tests." | |||
| 765 | trailing-string))) | 765 | trailing-string))) |
| 766 | 766 | ||
| 767 | (defun fz-make+zone (h &optional m s) | 767 | (defun fz-make+zone (h &optional m s) |
| 768 | "Creates a non-negative offset." | 768 | "Create a non-negative offset." |
| 769 | (declare (pure t)) | 769 | (declare (pure t)) |
| 770 | (let ((m (or m 0)) | 770 | (let ((m (or m 0)) |
| 771 | (s (or s 0))) | 771 | (s (or s 0))) |
| 772 | (+ (* 3600 h) (* 60 m) s))) | 772 | (+ (* 3600 h) (* 60 m) s))) |
| 773 | 773 | ||
| 774 | (defun fz-make-zone (h &optional m s) | 774 | (defun fz-make-zone (h &optional m s) |
| 775 | "Creates a negative offset. The arguments are all non-negative." | 775 | "Create a negative offset. The arguments are all non-negative." |
| 776 | (declare (pure t)) | 776 | (declare (pure t)) |
| 777 | (- (fz-make+zone h m s))) | 777 | (- (fz-make+zone h m s))) |
| 778 | 778 | ||
| 779 | (defmacro formatz-should-equal (zone expect) | 779 | (defmacro formatz-should-equal (zone expect) |
| 780 | "Formats ZONE and compares it to EXPECT. | 780 | "Format ZONE and compares it to EXPECT. |
| 781 | Uses the free variables `form-string' and `pattern-mod'. | 781 | Use the free variables `form-string' and `pattern-mod'. |
| 782 | The functions in `pattern-mod' are composed left to right." | 782 | The functions in `pattern-mod' are composed left to right." |
| 783 | (declare (debug t)) | 783 | (declare (debug t)) |
| 784 | `(let ((result ,expect)) | 784 | `(let ((result ,expect)) |
| @@ -790,7 +790,7 @@ The functions in `pattern-mod' are composed left to right." | |||
| 790 | ;; for hours, minutes, and seconds. | 790 | ;; for hours, minutes, and seconds. |
| 791 | 791 | ||
| 792 | (defun formatz-hours-exact-helper (form-string pattern-mod) | 792 | (defun formatz-hours-exact-helper (form-string pattern-mod) |
| 793 | "Tests format %z with whole hours." | 793 | "Test format %z with whole hours." |
| 794 | (formatz-should-equal (fz-make+zone 0) "+00") ;0 sign always +, both digits | 794 | (formatz-should-equal (fz-make+zone 0) "+00") ;0 sign always +, both digits |
| 795 | (formatz-should-equal (fz-make+zone 10) "+10") | 795 | (formatz-should-equal (fz-make+zone 10) "+10") |
| 796 | (formatz-should-equal (fz-make-zone 10) "-10") | 796 | (formatz-should-equal (fz-make-zone 10) "-10") |
| @@ -801,7 +801,7 @@ The functions in `pattern-mod' are composed left to right." | |||
| 801 | ) | 801 | ) |
| 802 | 802 | ||
| 803 | (defun formatz-nonzero-minutes-helper (form-string pattern-mod) | 803 | (defun formatz-nonzero-minutes-helper (form-string pattern-mod) |
| 804 | "Tests format %z with whole minutes." | 804 | "Test format %z with whole minutes." |
| 805 | (formatz-should-equal (fz-make+zone 0 30) "+00:30") ;has hours even though 0 | 805 | (formatz-should-equal (fz-make+zone 0 30) "+00:30") ;has hours even though 0 |
| 806 | (formatz-should-equal (fz-make-zone 0 30) "-00:30") | 806 | (formatz-should-equal (fz-make-zone 0 30) "-00:30") |
| 807 | (formatz-should-equal (fz-make+zone 0 4) "+00:04") | 807 | (formatz-should-equal (fz-make+zone 0 4) "+00:04") |
| @@ -819,7 +819,7 @@ The functions in `pattern-mod' are composed left to right." | |||
| 819 | ) | 819 | ) |
| 820 | 820 | ||
| 821 | (defun formatz-nonzero-seconds-helper (form-string pattern-mod) | 821 | (defun formatz-nonzero-seconds-helper (form-string pattern-mod) |
| 822 | "Tests format %z with non-0 seconds." | 822 | "Test format %z with non-0 seconds." |
| 823 | ;; non-0 seconds are always included | 823 | ;; non-0 seconds are always included |
| 824 | (formatz-should-equal (fz-make+zone 0 0 50) "+00:00:50") | 824 | (formatz-should-equal (fz-make+zone 0 0 50) "+00:00:50") |
| 825 | (formatz-should-equal (fz-make-zone 0 0 50) "-00:00:50") | 825 | (formatz-should-equal (fz-make-zone 0 0 50) "-00:00:50") |
| @@ -848,7 +848,7 @@ The functions in `pattern-mod' are composed left to right." | |||
| 848 | ) | 848 | ) |
| 849 | 849 | ||
| 850 | (defun formatz-hours-big-helper (form-string pattern-mod) | 850 | (defun formatz-hours-big-helper (form-string pattern-mod) |
| 851 | "Tests format %z with hours that don't fit in two digits." | 851 | "Test format %z with hours that don't fit in two digits." |
| 852 | (formatz-should-equal (fz-make+zone 101) "+101:00") | 852 | (formatz-should-equal (fz-make+zone 101) "+101:00") |
| 853 | (formatz-should-equal (fz-make+zone 123 10) "+123:10") | 853 | (formatz-should-equal (fz-make+zone 123 10) "+123:10") |
| 854 | (formatz-should-equal (fz-make-zone 123 10) "-123:10") | 854 | (formatz-should-equal (fz-make-zone 123 10) "-123:10") |
| @@ -857,7 +857,7 @@ The functions in `pattern-mod' are composed left to right." | |||
| 857 | ) | 857 | ) |
| 858 | 858 | ||
| 859 | (defun formatz-seconds-big-helper (form-string pattern-mod) | 859 | (defun formatz-seconds-big-helper (form-string pattern-mod) |
| 860 | "Tests format %z with hours greater than 99 and non-zero seconds." | 860 | "Test format %z with hours greater than 99 and non-zero seconds." |
| 861 | (formatz-should-equal (fz-make+zone 123 0 30) "+123:00:30") | 861 | (formatz-should-equal (fz-make+zone 123 0 30) "+123:00:30") |
| 862 | (formatz-should-equal (fz-make-zone 123 0 30) "-123:00:30") | 862 | (formatz-should-equal (fz-make-zone 123 0 30) "-123:00:30") |
| 863 | (formatz-should-equal (fz-make+zone 120 0 4) "+120:00:04") | 863 | (formatz-should-equal (fz-make+zone 120 0 4) "+120:00:04") |
| @@ -868,30 +868,30 @@ The functions in `pattern-mod' are composed left to right." | |||
| 868 | ;; use the above test cases for multiple formats. | 868 | ;; use the above test cases for multiple formats. |
| 869 | 869 | ||
| 870 | (defun formatz-mod-del-colons (string) | 870 | (defun formatz-mod-del-colons (string) |
| 871 | "Returns STRING with any colons removed." | 871 | "Return STRING with any colons removed." |
| 872 | (string-replace ":" "" string)) | 872 | (string-replace ":" "" string)) |
| 873 | 873 | ||
| 874 | (defun formatz-mod-add-00 (string) | 874 | (defun formatz-mod-add-00 (string) |
| 875 | "Returns STRING with \"00\" appended." | 875 | "Return STRING with \"00\" appended." |
| 876 | (concat string "00")) | 876 | (concat string "00")) |
| 877 | 877 | ||
| 878 | (defun formatz-mod-add-colon00 (string) | 878 | (defun formatz-mod-add-colon00 (string) |
| 879 | "Returns STRING with \":00\" appended." | 879 | "Return STRING with \":00\" appended." |
| 880 | (concat string ":00")) | 880 | (concat string ":00")) |
| 881 | 881 | ||
| 882 | (defun formatz-mod-pad-r10 (string) | 882 | (defun formatz-mod-pad-r10 (string) |
| 883 | "Returns STRING padded on the right to 10 characters." | 883 | "Return STRING padded on the right to 10 characters." |
| 884 | (concat string (make-string (- 10 (length string)) ?\s))) | 884 | (concat string (make-string (- 10 (length string)) ?\s))) |
| 885 | 885 | ||
| 886 | (defun formatz-mod-pad-r12 (string) | 886 | (defun formatz-mod-pad-r12 (string) |
| 887 | "Returns STRING padded on the right to 12 characters." | 887 | "Return STRING padded on the right to 12 characters." |
| 888 | (concat string (make-string (- 12 (length string)) ?\s))) | 888 | (concat string (make-string (- 12 (length string)) ?\s))) |
| 889 | 889 | ||
| 890 | ;; Convenience macro for generating groups of test cases. | 890 | ;; Convenience macro for generating groups of test cases. |
| 891 | 891 | ||
| 892 | (defmacro formatz-generate-tests | 892 | (defmacro formatz-generate-tests |
| 893 | (form-strings hour-mod mins-mod secs-mod big-mod secbig-mod) | 893 | (form-strings hour-mod mins-mod secs-mod big-mod secbig-mod) |
| 894 | "Defines tests for time formats FORM-STRINGS. | 894 | "Define tests for time formats FORM-STRINGS. |
| 895 | FORM-STRINGS is a list of formats, each \"%z\" or some variation thereof. | 895 | FORM-STRINGS is a list of formats, each \"%z\" or some variation thereof. |
| 896 | 896 | ||
| 897 | Each of the remaining arguments is an unquoted list of the form | 897 | Each of the remaining arguments is an unquoted list of the form |
| @@ -925,7 +925,7 @@ the other expected results for hours greater than 99 with non-zero seconds." | |||
| 925 | ert-test-list | 925 | ert-test-list |
| 926 | (list | 926 | (list |
| 927 | `(ert-deftest ,(intern (concat "formatz-" form-string "-hhmm")) () | 927 | `(ert-deftest ,(intern (concat "formatz-" form-string "-hhmm")) () |
| 928 | ,(concat "Tests time-stamp format " form-string | 928 | ,(concat "Test time-stamp format " form-string |
| 929 | " with whole hours or minutes.") | 929 | " with whole hours or minutes.") |
| 930 | (should (equal (formatz ,form-string (fz-make+zone 0)) | 930 | (should (equal (formatz ,form-string (fz-make+zone 0)) |
| 931 | ,(car hour-mod))) | 931 | ,(car hour-mod))) |
| @@ -934,13 +934,13 @@ the other expected results for hours greater than 99 with non-zero seconds." | |||
| 934 | ,(car mins-mod))) | 934 | ,(car mins-mod))) |
| 935 | (formatz-nonzero-minutes-helper ,form-string ',(cdr mins-mod))) | 935 | (formatz-nonzero-minutes-helper ,form-string ',(cdr mins-mod))) |
| 936 | `(ert-deftest ,(intern (concat "formatz-" form-string "-seconds")) () | 936 | `(ert-deftest ,(intern (concat "formatz-" form-string "-seconds")) () |
| 937 | ,(concat "Tests time-stamp format " form-string | 937 | ,(concat "Test time-stamp format " form-string |
| 938 | " with offsets that have non-zero seconds.") | 938 | " with offsets that have non-zero seconds.") |
| 939 | (should (equal (formatz ,form-string (fz-make+zone 0 0 30)) | 939 | (should (equal (formatz ,form-string (fz-make+zone 0 0 30)) |
| 940 | ,(car secs-mod))) | 940 | ,(car secs-mod))) |
| 941 | (formatz-nonzero-seconds-helper ,form-string ',(cdr secs-mod))) | 941 | (formatz-nonzero-seconds-helper ,form-string ',(cdr secs-mod))) |
| 942 | `(ert-deftest ,(intern (concat "formatz-" form-string "-threedigit")) () | 942 | `(ert-deftest ,(intern (concat "formatz-" form-string "-threedigit")) () |
| 943 | ,(concat "Tests time-stamp format " form-string | 943 | ,(concat "Test time-stamp format " form-string |
| 944 | " with offsets that are 100 hours or greater.") | 944 | " with offsets that are 100 hours or greater.") |
| 945 | (should (equal (formatz ,form-string (fz-make+zone 100)) | 945 | (should (equal (formatz ,form-string (fz-make+zone 100)) |
| 946 | ,(car big-mod))) | 946 | ,(car big-mod))) |
| @@ -981,7 +981,7 @@ the other expected results for hours greater than 99 with non-zero seconds." | |||
| 981 | ;; The legacy exception for %z in time-stamp will need to remain | 981 | ;; The legacy exception for %z in time-stamp will need to remain |
| 982 | ;; through at least 2024 and Emacs 28. | 982 | ;; through at least 2024 and Emacs 28. |
| 983 | (ert-deftest formatz-%z-spotcheck () | 983 | (ert-deftest formatz-%z-spotcheck () |
| 984 | "Spot-checks internal implementation of time-stamp format %z." | 984 | "Spot-check internal implementation of time-stamp format %z." |
| 985 | (should (equal (format-time-offset "%z" (fz-make+zone 0)) "+0000")) | 985 | (should (equal (format-time-offset "%z" (fz-make+zone 0)) "+0000")) |
| 986 | (should (equal (format-time-offset "%z" (fz-make+zone 0 30)) "+0030")) | 986 | (should (equal (format-time-offset "%z" (fz-make+zone 0 30)) "+0030")) |
| 987 | (should (equal (format-time-offset "%z" (fz-make+zone 0 0 30)) "+000030")) | 987 | (should (equal (format-time-offset "%z" (fz-make+zone 0 0 30)) "+000030")) |
| @@ -1104,7 +1104,7 @@ the other expected results for hours greater than 99 with non-zero seconds." | |||
| 1104 | ;;; Illegal %z formats | 1104 | ;;; Illegal %z formats |
| 1105 | 1105 | ||
| 1106 | (ert-deftest formatz-illegal-options () | 1106 | (ert-deftest formatz-illegal-options () |
| 1107 | "Tests that illegal/nonsensical/ambiguous %z formats don't produce output." | 1107 | "Test that illegal/nonsensical/ambiguous %z formats don't produce output." |
| 1108 | ;; multiple options | 1108 | ;; multiple options |
| 1109 | (should (equal "" (formatz "%_-z" 0))) | 1109 | (should (equal "" (formatz "%_-z" 0))) |
| 1110 | (should (equal "" (formatz "%-_z" 0))) | 1110 | (should (equal "" (formatz "%-_z" 0))) |