aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorPaul Eggert2019-08-20 17:34:03 -0700
committerPaul Eggert2019-08-20 17:36:46 -0700
commit396ed88a50fba95cd3b989965defef0130a42c42 (patch)
tree95b03c537acf8d65b6d894a283eccf9f1d31a1e8 /test/src
parent7e2090ee80c9099ee953392444e1d73d10e973d4 (diff)
downloademacs-396ed88a50fba95cd3b989965defef0130a42c42.tar.gz
emacs-396ed88a50fba95cd3b989965defef0130a42c42.zip
Avoid some excess precision in time arithmetic
* doc/misc/emacs-mime.texi (time-date): Adjust example to match new behavior. * etc/NEWS: Mention this. * lisp/calendar/time-date.el (decoded-time-add) (decoded-time--alter-second): Don’t lose underestimate precision of seconds component. * src/bignum.c (mpz): Grow by 1. * src/timefns.c (trillion_factor): New function. (timeform_sub_ps_p): Remove. (time_arith): Avoid unnecessarily-large hz, by reducing the hz to a value no worse than the worse hz of the two arguments. The result is always exact unless an error is signaled. * test/src/timefns-tests.el (timefns-tests--decode-time): New function. (format-time-string-with-zone): Test (decode-time LOOK ZONE t) resolution as well as its numeric value.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/timefns-tests.el44
1 files changed, 22 insertions, 22 deletions
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el
index 48d964d129c..3a18a4a24dd 100644
--- a/test/src/timefns-tests.el
+++ b/test/src/timefns-tests.el
@@ -19,6 +19,12 @@
19 19
20(require 'ert) 20(require 'ert)
21 21
22(defun timefns-tests--decode-time (look zone decoded-time)
23 (should (equal (decode-time look zone t) decoded-time))
24 (should (equal (decode-time look zone 'integer)
25 (cons (time-convert (car decoded-time) 'integer)
26 (cdr decoded-time)))))
27
22;;; Check format-time-string and decode-time with various TZ settings. 28;;; Check format-time-string and decode-time with various TZ settings.
23;;; Use only POSIX-compatible TZ values, since the tests should work 29;;; Use only POSIX-compatible TZ values, since the tests should work
24;;; even if tzdb is not in use. 30;;; even if tzdb is not in use.
@@ -40,31 +46,29 @@
40 (7879679999900 . 100000) 46 (7879679999900 . 100000)
41 (78796799999999999999 . 1000000000000))) 47 (78796799999999999999 . 1000000000000)))
42 ;; UTC. 48 ;; UTC.
43 (let ((sec (time-add 59 (time-subtract (time-convert look t) 49 (let* ((look-ticks-hz (time-convert look t))
44 (time-convert look 'integer))))) 50 (hz (cdr look-ticks-hz))
51 (look-integer (time-convert look 'integer))
52 (sec (time-add (time-convert 59 hz)
53 (time-subtract look-ticks-hz
54 (time-convert look-integer hz)))))
45 (should (string-equal 55 (should (string-equal
46 (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t) 56 (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t)
47 "1972-06-30 23:59:59.999 +0000")) 57 "1972-06-30 23:59:59.999 +0000"))
48 (should (equal (decode-time look t 'integer) 58 (timefns-tests--decode-time look t
49 '(59 59 23 30 6 1972 5 nil 0))) 59 (list sec 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)))
52 ;; "UTC0". 60 ;; "UTC0".
53 (should (string-equal 61 (should (string-equal
54 (format-time-string format look "UTC0") 62 (format-time-string format look "UTC0")
55 "1972-06-30 23:59:59.999 +0000 (UTC)")) 63 "1972-06-30 23:59:59.999 +0000 (UTC)"))
56 (should (equal (decode-time look "UTC0" 'integer) 64 (timefns-tests--decode-time look "UTC0"
57 '(59 59 23 30 6 1972 5 nil 0))) 65 (list sec 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)))
60 ;; Negative UTC offset, as a Lisp list. 66 ;; Negative UTC offset, as a Lisp list.
61 (should (string-equal 67 (should (string-equal
62 (format-time-string format look '(-28800 "PST")) 68 (format-time-string format look '(-28800 "PST"))
63 "1972-06-30 15:59:59.999 -0800 (PST)")) 69 "1972-06-30 15:59:59.999 -0800 (PST)"))
64 (should (equal (decode-time look '(-28800 "PST") 'integer) 70 (timefns-tests--decode-time look '(-28800 "PST")
65 '(59 59 15 30 6 1972 5 nil -28800))) 71 (list sec 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)))
68 ;; Negative UTC offset, as a Lisp integer. 72 ;; Negative UTC offset, as a Lisp integer.
69 (should (string-equal 73 (should (string-equal
70 (format-time-string format look -28800) 74 (format-time-string format look -28800)
@@ -73,18 +77,14 @@
73 (if (eq system-type 'windows-nt) 77 (if (eq system-type 'windows-nt)
74 "1972-06-30 15:59:59.999 -0800 (ZZZ)" 78 "1972-06-30 15:59:59.999 -0800 (ZZZ)"
75 "1972-06-30 15:59:59.999 -0800 (-08)"))) 79 "1972-06-30 15:59:59.999 -0800 (-08)")))
76 (should (equal (decode-time look -28800 'integer) 80 (timefns-tests--decode-time look -28800
77 '(59 59 15 30 6 1972 5 nil -28800))) 81 (list sec 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)))
80 ;; Positive UTC offset that is not an hour multiple, as a string. 82 ;; Positive UTC offset that is not an hour multiple, as a string.
81 (should (string-equal 83 (should (string-equal
82 (format-time-string format look "IST-5:30") 84 (format-time-string format look "IST-5:30")
83 "1972-07-01 05:29:59.999 +0530 (IST)")) 85 "1972-07-01 05:29:59.999 +0530 (IST)"))
84 (should (equal (decode-time look "IST-5:30" 'integer) 86 (timefns-tests--decode-time look "IST-5:30"
85 '(59 29 5 1 7 1972 6 nil 19800))) 87 (list sec 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)))))))
88 88
89(ert-deftest decode-then-encode-time () 89(ert-deftest decode-then-encode-time ()
90 (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