diff options
| author | Lars Ingebrigtsen | 2019-07-29 14:15:03 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-07-29 14:22:38 +0200 |
| commit | 6cfda69d72cb9debefc48d0d95e341d389e7303a (patch) | |
| tree | 031f4d820ab5a0113f25a4d9096c0c5fde98499d /test | |
| parent | e4f957fb0794b5616deb0abf792e11132c06e3a9 (diff) | |
| download | emacs-6cfda69d72cb9debefc48d0d95e341d389e7303a.tar.gz emacs-6cfda69d72cb9debefc48d0d95e341d389e7303a.zip | |
Add support for dealing with decoded time structures
* doc/lispref/os.texi (Time Conversion): Document the new
functions that work on decoded time.
(Time Calculations): Document new date/time functions.
* lisp/simple.el (decoded-time-second, decoded-time-minute)
(decoded-time-hour, decoded-time-day, decoded-time-month)
(decoded-time-year, decoded-time-weekday, decoded-time-dst)
(decoded-time-zone): New accessor functions for decoded time values.
* lisp/calendar/time-date.el (date-days-in-month)
(date-ordinal-to-time): New functions.
(decoded-time--alter-month, decoded-time--alter-day)
(decoded-time--alter-second, make-decoded-time): New functions
added to manipulate decoded time structures.
* src/timefns.c (Fdecode_time): Mention the new accessors.
* test/lisp/calendar/time-date-tests.el: New file to test the
decoded time functions and the other new functions.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/calendar/time-date-tests.el | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/test/lisp/calendar/time-date-tests.el b/test/lisp/calendar/time-date-tests.el new file mode 100644 index 00000000000..d6cf742bc53 --- /dev/null +++ b/test/lisp/calendar/time-date-tests.el | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | ;;; time-date-tests.el --- tests for calendar/time-date.el -*- lexical-binding:t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2019 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Code: | ||
| 21 | |||
| 22 | (require 'ert) | ||
| 23 | (require 'time-date) | ||
| 24 | |||
| 25 | (ert-deftest test-leap-year () | ||
| 26 | (should-not (date-leap-year-p 1999)) | ||
| 27 | (should-not (date-leap-year-p 1900)) | ||
| 28 | (should (date-leap-year-p 2000)) | ||
| 29 | (should (date-leap-year-p 2004))) | ||
| 30 | |||
| 31 | (ert-deftest test-days-in-month () | ||
| 32 | (should (= (date-days-in-month 2004 2) 29)) | ||
| 33 | (should (= (date-days-in-month 2004 3) 31)) | ||
| 34 | (should-not (= (date-days-in-month 1900 3) 28))) | ||
| 35 | |||
| 36 | (ert-deftest test-ordinal () | ||
| 37 | (should (equal (date-ordinal-to-time 2008 271) | ||
| 38 | '(0 0 0 27 9 2008 nil nil nil))) | ||
| 39 | (should (equal (date-ordinal-to-time 2008 1) | ||
| 40 | '(0 0 0 1 1 2008 nil nil nil))) | ||
| 41 | (should (equal (date-ordinal-to-time 2008 32) | ||
| 42 | '(0 0 0 1 2 2008 nil nil nil))) | ||
| 43 | (should (equal (date-ordinal-to-time 1981 095) | ||
| 44 | '(0 0 0 5 4 1981 nil nil nil)))) | ||
| 45 | |||
| 46 | (cl-defmethod mdec (&key second minute hour | ||
| 47 | day month year | ||
| 48 | dst zone) | ||
| 49 | (list second minute hour day month year nil dst zone)) | ||
| 50 | |||
| 51 | (ert-deftest test-decoded-add () | ||
| 52 | (let ((time '(12 15 16 8 7 2019 1 t 7200))) | ||
| 53 | (should (equal (decoded-time-add time (mdec :year 1)) | ||
| 54 | '(12 15 16 8 7 2020 1 t 7200))) | ||
| 55 | |||
| 56 | (should (equal (decoded-time-add time (mdec :year -2)) | ||
| 57 | '(12 15 16 8 7 2017 1 t 7200))) | ||
| 58 | |||
| 59 | (should (equal (decoded-time-add time (mdec :month 1)) | ||
| 60 | '(12 15 16 8 8 2019 1 t 7200))) | ||
| 61 | |||
| 62 | (should (equal (decoded-time-add time (mdec :month 10)) | ||
| 63 | '(12 15 16 8 5 2020 1 t 7200))) | ||
| 64 | |||
| 65 | (should (equal (decoded-time-add time (mdec :day 1)) | ||
| 66 | '(12 15 16 9 7 2019 1 t 7200))) | ||
| 67 | |||
| 68 | (should (equal (decoded-time-add time (mdec :day -1)) | ||
| 69 | '(12 15 16 7 7 2019 1 t 7200))) | ||
| 70 | |||
| 71 | (should (equal (decoded-time-add time (mdec :day 30)) | ||
| 72 | '(12 15 16 7 8 2019 1 t 7200))) | ||
| 73 | |||
| 74 | (should (equal (decoded-time-add time (mdec :day -365)) | ||
| 75 | '(12 15 16 8 7 2018 1 t 7200))) | ||
| 76 | |||
| 77 | (should (equal (decoded-time-add time (mdec :day 365)) | ||
| 78 | '(12 15 16 7 7 2020 1 t 7200))) | ||
| 79 | |||
| 80 | ;; 2020 is a leap year. | ||
| 81 | (should (equal (decoded-time-add time (mdec :day 366)) | ||
| 82 | '(12 15 16 8 7 2020 1 t 7200))) | ||
| 83 | |||
| 84 | (should (equal (decoded-time-add time (mdec :second 1)) | ||
| 85 | '(13 15 16 8 7 2019 1 t 7200))) | ||
| 86 | |||
| 87 | (should (equal (decoded-time-add time (mdec :second -1)) | ||
| 88 | '(11 15 16 8 7 2019 1 t 7200))) | ||
| 89 | |||
| 90 | (should (equal (decoded-time-add time (mdec :second 61)) | ||
| 91 | '(13 16 16 8 7 2019 1 t 7200))) | ||
| 92 | |||
| 93 | (should (equal (decoded-time-add time (mdec :hour 1 :minute 2 :second 3)) | ||
| 94 | '(15 17 17 8 7 2019 1 t 7200))) | ||
| 95 | |||
| 96 | (should (equal (decoded-time-add time (mdec :hour 24)) | ||
| 97 | '(12 15 16 9 7 2019 1 t 7200))) | ||
| 98 | )) | ||
| 99 | |||
| 100 | (ert-deftest test-decoded-add-zone () | ||
| 101 | (let ((time '(12 15 16 8 7 2019 1 t 7200))) | ||
| 102 | (should (equal (decoded-time-add time (mdec :zone -3600)) | ||
| 103 | '(12 15 15 8 7 2019 1 t 7200))) | ||
| 104 | (should (equal (decoded-time-add time (mdec :zone -7200)) | ||
| 105 | '(12 15 14 8 7 2019 1 t 7200))))) | ||
| 106 | |||
| 107 | (require 'ert) | ||
| 108 | |||
| 109 | ;;; time-date-tests.el ends here | ||