aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2019-08-16 18:08:23 -0700
committerPaul Eggert2019-08-16 18:12:24 -0700
commitf6dd46cba8b144cf1653f8314a4b629beee11be3 (patch)
tree3ff60f25fee220b79711492eb11892e65518272e /src
parentf9fd12a30b3d94eb48f7b309907d136d7b2682ac (diff)
downloademacs-f6dd46cba8b144cf1653f8314a4b629beee11be3.tar.gz
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')
-rw-r--r--src/timefns.c16
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)
1040 1040
1041 enum timeform aform, bform; 1041 enum timeform aform, bform;
1042 struct lisp_time ta = lisp_time_struct (a, &aform); 1042 struct lisp_time ta = lisp_time_struct (a, &aform);
1043 struct lisp_time tb = lisp_time_struct (b, &bform); 1043
1044 /* Subtract nil from nil correctly, and handle other eq values
1045 quicker while we're at it. Compare here rather than earlier, to
1046 handle NaNs and check formats. */
1047 struct lisp_time tb;
1048 if (EQ (a, b))
1049 bform = aform, tb = ta;
1050 else
1051 tb = lisp_time_struct (b, &bform);
1052
1044 Lisp_Object ticks, hz; 1053 Lisp_Object ticks, hz;
1045 1054
1046 if (FASTER_TIMEFNS && EQ (ta.hz, tb.hz)) 1055 if (FASTER_TIMEFNS && EQ (ta.hz, tb.hz))
@@ -1125,8 +1134,9 @@ time_cmp (Lisp_Object a, Lisp_Object b)
1125 1134
1126 struct lisp_time ta = lisp_time_struct (a, 0); 1135 struct lisp_time ta = lisp_time_struct (a, 0);
1127 1136
1128 /* Compare nil to nil correctly, and other eq values while we're at it. 1137 /* Compare nil to nil correctly, and handle other eq values quicker
1129 Compare here rather than earlier, to handle NaNs and check formats. */ 1138 while we're at it. Compare here rather than earlier, to handle
1139 NaNs and check formats. */
1130 if (EQ (a, b)) 1140 if (EQ (a, b))
1131 return 0; 1141 return 0;
1132 1142