emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master f6dd46c 1/2: Subtracting “now” from “now” should y


From: Paul Eggert
Subject: [Emacs-diffs] master f6dd46c 1/2: Subtracting “now” from “now” should yield zero
Date: Fri, 16 Aug 2019 21:12:30 -0400 (EDT)

branch: master
commit f6dd46cba8b144cf1653f8314a4b629beee11be3
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    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.
---
 src/timefns.c                         | 16 +++++++++++++---
 test/lisp/calendar/time-date-tests.el |  3 ++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/timefns.c b/src/timefns.c
index a4c1c4c..979550c 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 b46a247..827d2c9 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]