diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2019-08-20 17:34:03 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2019-08-20 17:36:46 -0700 |
commit | 396ed88a50fba95cd3b989965defef0130a42c42 (patch) | |
tree | 95b03c537acf8d65b6d894a283eccf9f1d31a1e8 /test/src/timefns-tests.el | |
parent | 7e2090ee80c9099ee953392444e1d73d10e973d4 (diff) | |
download | emacs-396ed88a50fba95cd3b989965defef0130a42c42.tar.gz emacs-396ed88a50fba95cd3b989965defef0130a42c42.tar.bz2 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/timefns-tests.el')
-rw-r--r-- | test/src/timefns-tests.el | 44 |
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 @@ (require 'ert) +(defun timefns-tests--decode-time (look zone decoded-time) + (should (equal (decode-time look zone t) decoded-time)) + (should (equal (decode-time look zone 'integer) + (cons (time-convert (car decoded-time) 'integer) + (cdr decoded-time))))) + ;;; Check format-time-string and decode-time with various TZ settings. ;;; Use only POSIX-compatible TZ values, since the tests should work ;;; even if tzdb is not in use. @@ -40,31 +46,29 @@ (7879679999900 . 100000) (78796799999999999999 . 1000000000000))) ;; UTC. - (let ((sec (time-add 59 (time-subtract (time-convert look t) - (time-convert look 'integer))))) + (let* ((look-ticks-hz (time-convert look t)) + (hz (cdr look-ticks-hz)) + (look-integer (time-convert look 'integer)) + (sec (time-add (time-convert 59 hz) + (time-subtract look-ticks-hz + (time-convert look-integer hz))))) (should (string-equal (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t) "1972-06-30 23:59:59.999 +0000")) - (should (equal (decode-time look t 'integer) - '(59 59 23 30 6 1972 5 nil 0))) - (should (equal (decode-time look t t) - (list sec 59 23 30 6 1972 5 nil 0))) + (timefns-tests--decode-time look t + (list sec 59 23 30 6 1972 5 nil 0)) ;; "UTC0". (should (string-equal (format-time-string format look "UTC0") "1972-06-30 23:59:59.999 +0000 (UTC)")) - (should (equal (decode-time look "UTC0" 'integer) - '(59 59 23 30 6 1972 5 nil 0))) - (should (equal (decode-time look "UTC0" t) - (list sec 59 23 30 6 1972 5 nil 0))) + (timefns-tests--decode-time look "UTC0" + (list sec 59 23 30 6 1972 5 nil 0)) ;; Negative UTC offset, as a Lisp list. (should (string-equal (format-time-string format look '(-28800 "PST")) "1972-06-30 15:59:59.999 -0800 (PST)")) - (should (equal (decode-time look '(-28800 "PST") 'integer) - '(59 59 15 30 6 1972 5 nil -28800))) - (should (equal (decode-time look '(-28800 "PST") t) - (list sec 59 15 30 6 1972 5 nil -28800))) + (timefns-tests--decode-time look '(-28800 "PST") + (list sec 59 15 30 6 1972 5 nil -28800)) ;; Negative UTC offset, as a Lisp integer. (should (string-equal (format-time-string format look -28800) @@ -73,18 +77,14 @@ (if (eq system-type 'windows-nt) "1972-06-30 15:59:59.999 -0800 (ZZZ)" "1972-06-30 15:59:59.999 -0800 (-08)"))) - (should (equal (decode-time look -28800 'integer) - '(59 59 15 30 6 1972 5 nil -28800))) - (should (equal (decode-time look -28800 t) - (list sec 59 15 30 6 1972 5 nil -28800))) + (timefns-tests--decode-time look -28800 + (list sec 59 15 30 6 1972 5 nil -28800)) ;; Positive UTC offset that is not an hour multiple, as a string. (should (string-equal (format-time-string format look "IST-5:30") "1972-07-01 05:29:59.999 +0530 (IST)")) - (should (equal (decode-time look "IST-5:30" 'integer) - '(59 29 5 1 7 1972 6 nil 19800))) - (should (equal (decode-time look "IST-5:30" t) - (list sec 29 5 1 7 1972 6 nil 19800))))))) + (timefns-tests--decode-time look "IST-5:30" + (list sec 29 5 1 7 1972 6 nil 19800)))))) (ert-deftest decode-then-encode-time () (let ((time-values (list 0 -2 1 0.0 -0.0 -2.0 1.0 |