summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-08-16 18:08:23 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2019-08-16 18:12:24 -0700
commitf6dd46cba8b144cf1653f8314a4b629beee11be3 (patch)
tree3ff60f25fee220b79711492eb11892e65518272e
parentf9fd12a30b3d94eb48f7b309907d136d7b2682ac (diff)
downloademacs-f6dd46cba8b144cf1653f8314a4b629beee11be3.tar.gz
Subtracting “now” from “now” should yield zero
* src/timefns.c (time_arith): Arrange for (time-subtract nil nil) to yield 0, to be consistent with (time-equal-p nil nil). * test/lisp/calendar/time-date-tests.el (test-time-since): New test.
-rw-r--r--src/timefns.c16
-rw-r--r--test/lisp/calendar/time-date-tests.el3
2 files changed, 15 insertions, 4 deletions
diff --git a/src/timefns.c b/src/timefns.c
index a4c1c4cb284..979550c8431 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1040,7 +1040,16 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
enum timeform aform, bform;
struct lisp_time ta = lisp_time_struct (a, &aform);
- struct lisp_time tb = lisp_time_struct (b, &bform);
+
+ /* Subtract nil from nil correctly, and handle other eq values
+ quicker while we're at it. Compare here rather than earlier, to
+ handle NaNs and check formats. */
+ struct lisp_time tb;
+ if (EQ (a, b))
+ bform = aform, tb = ta;
+ else
+ tb = lisp_time_struct (b, &bform);
+
Lisp_Object ticks, hz;
if (FASTER_TIMEFNS && EQ (ta.hz, tb.hz))
@@ -1125,8 +1134,9 @@ time_cmp (Lisp_Object a, Lisp_Object b)
struct lisp_time ta = lisp_time_struct (a, 0);
- /* Compare nil to nil correctly, and other eq values while we're at it.
- Compare here rather than earlier, to handle NaNs and check formats. */
+ /* Compare nil to nil correctly, and handle other eq values quicker
+ while we're at it. Compare here rather than earlier, to handle
+ NaNs and check formats. */
if (EQ (a, b))
return 0;
diff --git a/test/lisp/calendar/time-date-tests.el b/test/lisp/calendar/time-date-tests.el
index b46a247cd30..827d2c9800a 100644
--- a/test/lisp/calendar/time-date-tests.el
+++ b/test/lisp/calendar/time-date-tests.el
@@ -104,6 +104,7 @@
(should (equal (decoded-time-add time (mdec :zone -7200))
'(12 15 14 8 7 2019 1 t 7200)))))
-(require 'ert)
+(ert-deftest test-time-since ()
+ (should (time-equal-p 0 (time-since nil))))
;;; time-date-tests.el ends here