diff options
| author | Lars Ingebrigtsen | 2019-07-30 16:56:12 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-07-31 21:47:29 +0200 |
| commit | 46df7bbe12cce4c9af7ce4357aa9f8d36c1d8933 (patch) | |
| tree | bb2e88c7866ff6984a2398ec74c69a58bac8b7d5 | |
| parent | 07ce3be6aa15fdf2092bdf3c60a132d5f4b9c980 (diff) | |
| download | emacs-46df7bbe12cce4c9af7ce4357aa9f8d36c1d8933.tar.gz emacs-46df7bbe12cce4c9af7ce4357aa9f8d36c1d8933.zip | |
Add new function time-zone-format
* lisp/calendar/time-date.el (time-zone-format): New function.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/calendar/time-date.el | 10 | ||||
| -rw-r--r-- | test/lisp/calendar/time-date-tests.el | 6 |
3 files changed, 20 insertions, 0 deletions
| @@ -2110,6 +2110,10 @@ doing computations on a decoded time structure), 'make-decoded-time' | |||
| 2110 | filled out), and 'encoded-time-set-defaults' (which fills in nil | 2110 | filled out), and 'encoded-time-set-defaults' (which fills in nil |
| 2111 | elements as if it's midnight January 1st, 1970) have been added. | 2111 | elements as if it's midnight January 1st, 1970) have been added. |
| 2112 | 2112 | ||
| 2113 | *** The new function `time-zone-format' has been added to format | ||
| 2114 | Emacs time zones (which are in seconds) according to many standards | ||
| 2115 | (i.e., "+01:00"). | ||
| 2116 | |||
| 2113 | ** 'define-minor-mode' automatically documents the meaning of ARG. | 2117 | ** 'define-minor-mode' automatically documents the meaning of ARG. |
| 2114 | 2118 | ||
| 2115 | +++ | 2119 | +++ |
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index f14478e67cc..efc9ae4e3b9 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el | |||
| @@ -352,6 +352,16 @@ is output until the first non-zero unit is encountered." | |||
| 352 | (<= (car here) delay))) | 352 | (<= (car here) delay))) |
| 353 | (concat (format "%.2f" (/ delay (car (cddr here)))) (cadr here)))))) | 353 | (concat (format "%.2f" (/ delay (car (cddr here)))) (cadr here)))))) |
| 354 | 354 | ||
| 355 | (defun time-zone-format (seconds) | ||
| 356 | "Format SECONDS as a valid time zone string. | ||
| 357 | For instance, 3600 is \"+01:00\"." | ||
| 358 | (format "%s%02d:%02d" | ||
| 359 | (if (< seconds 0) | ||
| 360 | "-" | ||
| 361 | "+") | ||
| 362 | (/ (abs seconds) 3600) | ||
| 363 | (mod (abs seconds) 3600))) | ||
| 364 | |||
| 355 | (defun date-days-in-month (year month) | 365 | (defun date-days-in-month (year month) |
| 356 | "The number of days in MONTH in YEAR." | 366 | "The number of days in MONTH in YEAR." |
| 357 | (if (= month 2) | 367 | (if (= month 2) |
diff --git a/test/lisp/calendar/time-date-tests.el b/test/lisp/calendar/time-date-tests.el index b46a247cd30..51250ce5e7a 100644 --- a/test/lisp/calendar/time-date-tests.el +++ b/test/lisp/calendar/time-date-tests.el | |||
| @@ -104,6 +104,12 @@ | |||
| 104 | (should (equal (decoded-time-add time (mdec :zone -7200)) | 104 | (should (equal (decoded-time-add time (mdec :zone -7200)) |
| 105 | '(12 15 14 8 7 2019 1 t 7200))))) | 105 | '(12 15 14 8 7 2019 1 t 7200))))) |
| 106 | 106 | ||
| 107 | (ert-deftest test-time-zone-format () | ||
| 108 | (should (equal (time-zone-format 3600) | ||
| 109 | "+01:00")) | ||
| 110 | (should (equal (time-zone-format -7200) | ||
| 111 | "-02:00"))) | ||
| 112 | |||
| 107 | (require 'ert) | 113 | (require 'ert) |
| 108 | 114 | ||
| 109 | ;;; time-date-tests.el ends here | 115 | ;;; time-date-tests.el ends here |