diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2019-08-16 18:08:23 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2019-08-16 18:12:24 -0700 |
commit | f6dd46cba8b144cf1653f8314a4b629beee11be3 (patch) | |
tree | 3ff60f25fee220b79711492eb11892e65518272e /src/timefns.c | |
parent | f9fd12a30b3d94eb48f7b309907d136d7b2682ac (diff) | |
download | emacs-f6dd46cba8b144cf1653f8314a4b629beee11be3.tar.gz emacs-f6dd46cba8b144cf1653f8314a4b629beee11be3.tar.bz2 emacs-f6dd46cba8b144cf1653f8314a4b629beee11be3.zip |
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.
Diffstat (limited to 'src/timefns.c')
-rw-r--r-- | src/timefns.c | 16 |
1 files changed, 13 insertions, 3 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; |