diff options
| author | Paul Eggert | 2019-08-16 22:09:04 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-08-16 23:25:07 -0700 |
| commit | 37257d6acadff17bd1e52cfa460950bcb684c5c3 (patch) | |
| tree | ab7088cfa725561c8456f388cff79466948b3532 /test/src | |
| parent | d7c9ed8445d13de7350be3360d68717362f89929 (diff) | |
| download | emacs-37257d6acadff17bd1e52cfa460950bcb684c5c3.tar.gz emacs-37257d6acadff17bd1e52cfa460950bcb684c5c3.zip | |
More-compatible subsecond calendrical timestamps
Instead of appending a subseconds member to the result of
‘decode-time’, this keeps the format unchanged unless you give
a new optional argument to ‘decode-time’. Also, the augmented
format now puts the subsecond info in the SECONDS element, so
the total number of elements is unchanged; this is more
compatible with code that expects the traditional 9 elements,
such as ‘(pcase decoded-time (`(,SEC ,MIN ,HOUR ,DAY ,MON
,YEAR ,DOW ,DST ,ZONE) ...) ...)’.
* doc/lispref/os.texi, doc/misc/emacs-mime.texi, etc/NEWS:
* lisp/net/soap-client.el (soap-decode-date-time):
* lisp/simple.el (decoded-time):
Document the new behavior.
* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
* lisp/calendar/iso8601.el (iso8601-parse)
(iso8601-parse-time, iso8601-parse-duration)
(iso8601--decoded-time):
* lisp/calendar/parse-time.el (parse-time-string):
* lisp/calendar/time-date.el (decoded-time-add)
(decoded-time--alter-second):
* lisp/org/org.el (org-parse-time-string):
* lisp/simple.el (decoded-time):
* src/timefns.c (Fdecode_time, Fencode_time):
* test/lisp/calendar/icalendar-tests.el:
(icalendar--decode-isodatetime):
* test/lisp/calendar/iso8601-tests.el (test-iso8601-date-years)
(test-iso8601-date-dates, test-iso8601-date-obsolete)
(test-iso8601-date-weeks, test-iso8601-date-ordinals)
(test-iso8601-time, test-iso8601-combined)
(test-iso8601-duration, test-iso8601-intervals)
(standard-test-dates, standard-test-time-of-day-fractions)
(standard-test-time-of-day-beginning-of-day)
(standard-test-time-of-day-utc)
(standard-test-time-of-day-zone)
(standard-test-date-and-time-of-day, standard-test-interval):
* test/lisp/calendar/parse-time-tests.el (parse-time-tests):
* test/src/timefns-tests.el (format-time-string-with-zone)
(encode-time-dst-numeric-zone):
Revert recent changes that added a SUBSECS member to
calendrical timestamps, since that component is no longer
present (the info, if any, is now in the SECONDS member).
* lisp/calendar/time-date.el (decoded-time-add)
(decoded-time--alter-second):
Support fractional seconds in the new form. Simplify.
* src/timefns.c (Fdecode_time): Support new arg FORM.
(Fencode_time): Support subsecond resolution.
* test/src/timefns-tests.el (format-time-string-with-zone)
(decode-then-encode-time): Test subsecond calendrical timestamps.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/timefns-tests.el | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el index 362e7655a91..13ab7d83c3e 100644 --- a/test/src/timefns-tests.el +++ b/test/src/timefns-tests.el | |||
| @@ -40,25 +40,31 @@ | |||
| 40 | (7879679999900 . 100000) | 40 | (7879679999900 . 100000) |
| 41 | (78796799999999999999 . 1000000000000))) | 41 | (78796799999999999999 . 1000000000000))) |
| 42 | ;; UTC. | 42 | ;; UTC. |
| 43 | (let ((subsec (time-subtract (time-convert look t) | 43 | (let ((sec (time-add 59 (time-subtract (time-convert look t) |
| 44 | (time-convert look 'integer)))) | 44 | (time-convert look 'integer))))) |
| 45 | (should (string-equal | 45 | (should (string-equal |
| 46 | (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t) | 46 | (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t) |
| 47 | "1972-06-30 23:59:59.999 +0000")) | 47 | "1972-06-30 23:59:59.999 +0000")) |
| 48 | (should (equal (decode-time look t) | 48 | (should (equal (decode-time look t 'integer) |
| 49 | (list 59 59 23 30 6 1972 5 nil 0 subsec))) | 49 | '(59 59 23 30 6 1972 5 nil 0))) |
| 50 | (should (equal (decode-time look t t) | ||
| 51 | (list sec 59 23 30 6 1972 5 nil 0))) | ||
| 50 | ;; "UTC0". | 52 | ;; "UTC0". |
| 51 | (should (string-equal | 53 | (should (string-equal |
| 52 | (format-time-string format look "UTC0") | 54 | (format-time-string format look "UTC0") |
| 53 | "1972-06-30 23:59:59.999 +0000 (UTC)")) | 55 | "1972-06-30 23:59:59.999 +0000 (UTC)")) |
| 54 | (should (equal (decode-time look "UTC0") | 56 | (should (equal (decode-time look "UTC0" 'integer) |
| 55 | (list 59 59 23 30 6 1972 5 nil 0 subsec))) | 57 | '(59 59 23 30 6 1972 5 nil 0))) |
| 58 | (should (equal (decode-time look "UTC0" t) | ||
| 59 | (list sec 59 23 30 6 1972 5 nil 0))) | ||
| 56 | ;; Negative UTC offset, as a Lisp list. | 60 | ;; Negative UTC offset, as a Lisp list. |
| 57 | (should (string-equal | 61 | (should (string-equal |
| 58 | (format-time-string format look '(-28800 "PST")) | 62 | (format-time-string format look '(-28800 "PST")) |
| 59 | "1972-06-30 15:59:59.999 -0800 (PST)")) | 63 | "1972-06-30 15:59:59.999 -0800 (PST)")) |
| 60 | (should (equal (decode-time look '(-28800 "PST")) | 64 | (should (equal (decode-time look '(-28800 "PST") 'integer) |
| 61 | (list 59 59 15 30 6 1972 5 nil -28800 subsec))) | 65 | '(59 59 15 30 6 1972 5 nil -28800))) |
| 66 | (should (equal (decode-time look '(-28800 "PST") t) | ||
| 67 | (list sec 59 15 30 6 1972 5 nil -28800))) | ||
| 62 | ;; Negative UTC offset, as a Lisp integer. | 68 | ;; Negative UTC offset, as a Lisp integer. |
| 63 | (should (string-equal | 69 | (should (string-equal |
| 64 | (format-time-string format look -28800) | 70 | (format-time-string format look -28800) |
| @@ -67,14 +73,18 @@ | |||
| 67 | (if (eq system-type 'windows-nt) | 73 | (if (eq system-type 'windows-nt) |
| 68 | "1972-06-30 15:59:59.999 -0800 (ZZZ)" | 74 | "1972-06-30 15:59:59.999 -0800 (ZZZ)" |
| 69 | "1972-06-30 15:59:59.999 -0800 (-08)"))) | 75 | "1972-06-30 15:59:59.999 -0800 (-08)"))) |
| 70 | (should (equal (decode-time look -28800) | 76 | (should (equal (decode-time look -28800 'integer) |
| 71 | (list 59 59 15 30 6 1972 5 nil -28800 subsec))) | 77 | '(59 59 15 30 6 1972 5 nil -28800))) |
| 78 | (should (equal (decode-time look -28800 t) | ||
| 79 | (list sec 59 15 30 6 1972 5 nil -28800))) | ||
| 72 | ;; Positive UTC offset that is not an hour multiple, as a string. | 80 | ;; Positive UTC offset that is not an hour multiple, as a string. |
| 73 | (should (string-equal | 81 | (should (string-equal |
| 74 | (format-time-string format look "IST-5:30") | 82 | (format-time-string format look "IST-5:30") |
| 75 | "1972-07-01 05:29:59.999 +0530 (IST)")) | 83 | "1972-07-01 05:29:59.999 +0530 (IST)")) |
| 76 | (should (equal (decode-time look "IST-5:30") | 84 | (should (equal (decode-time look "IST-5:30" 'integer) |
| 77 | (list 59 29 5 1 7 1972 6 nil 19800 subsec))))))) | 85 | '(59 29 5 1 7 1972 6 nil 19800))) |
| 86 | (should (equal (decode-time look "IST-5:30" t) | ||
| 87 | (list sec 29 5 1 7 1972 6 nil 19800))))))) | ||
| 78 | 88 | ||
| 79 | (ert-deftest decode-then-encode-time () | 89 | (ert-deftest decode-then-encode-time () |
| 80 | (let ((time-values (list 0 -2 1 0.0 -0.0 -2.0 1.0 | 90 | (let ((time-values (list 0 -2 1 0.0 -0.0 -2.0 1.0 |
| @@ -87,11 +97,13 @@ | |||
| 87 | (cons (1+ most-positive-fixnum) 1000000000000) | 97 | (cons (1+ most-positive-fixnum) 1000000000000) |
| 88 | (cons 1000000000000 (1+ most-positive-fixnum))))) | 98 | (cons 1000000000000 (1+ most-positive-fixnum))))) |
| 89 | (dolist (a time-values) | 99 | (dolist (a time-values) |
| 90 | (let* ((d (ignore-errors (decode-time a t))) | 100 | (let* ((d (ignore-errors (decode-time a t t))) |
| 101 | (d-integer (ignore-errors (decode-time a t 'integer))) | ||
| 91 | (e (if d (encode-time d))) | 102 | (e (if d (encode-time d))) |
| 92 | (diff (float-time (time-subtract a e)))) | 103 | (e-integer (if d-integer (encode-time d-integer)))) |
| 93 | (should (or (not d) | 104 | (should (or (not d) (time-equal-p a e))) |
| 94 | (and (<= 0 diff) (< diff 1)))))))) | 105 | (should (or (not d-integer) (time-equal-p (time-convert a 'integer) |
| 106 | e-integer))))))) | ||
| 95 | 107 | ||
| 96 | ;;; This should not dump core. | 108 | ;;; This should not dump core. |
| 97 | (ert-deftest format-time-string-with-outlandish-zone () | 109 | (ert-deftest format-time-string-with-outlandish-zone () |
| @@ -151,7 +163,7 @@ | |||
| 151 | (ert-deftest encode-time-dst-numeric-zone () | 163 | (ert-deftest encode-time-dst-numeric-zone () |
| 152 | "Check for Bug#35502." | 164 | "Check for Bug#35502." |
| 153 | (should (time-equal-p | 165 | (should (time-equal-p |
| 154 | (encode-time '(29 31 17 30 4 2019 2 t 7200 0)) | 166 | (encode-time '(29 31 17 30 4 2019 2 t 7200)) |
| 155 | '(23752 27217)))) | 167 | '(23752 27217)))) |
| 156 | 168 | ||
| 157 | (ert-deftest float-time-precision () | 169 | (ert-deftest float-time-precision () |