From 9d4633e934da77bc1c3617a9450ee17151f35271 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 1 Aug 2022 00:38:32 -0700 Subject: [PATCH] (time-equal-p nil X) returns nil * src/timefns.c (Ftime_equal_p): nil compares unequal to non-nil. --- doc/lispref/os.texi | 7 ++++++- src/timefns.c | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index 2b49818ed33..5fb34fb9b66 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi @@ -2067,7 +2067,12 @@ This returns @code{t} if the time value @var{t1} is less than the time value @defun time-equal-p t1 t2 This returns @code{t} if the two time values @var{t1} and @var{t2} are -equal. +equal. The result is @code{nil} if either argument is a NaN. +For the purpose of comparison, a @code{nil} argument represents the +current time with infinite resolution, so this function returns +@code{nil} if one argument is @code{nil} and the other is not, and +callers can therefore use @code{nil} to represent an unknown time +value that does not equal any timestamp. @end defun @defun time-subtract t1 t2 diff --git a/src/timefns.c b/src/timefns.c index 9df50eaecc3..25bfda513c2 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -1258,7 +1258,9 @@ DEFUN ("time-equal-p", Ftime_equal_p, Stime_equal_p, 2, 2, 0, See `format-time-string' for the various forms of a time value. */) (Lisp_Object a, Lisp_Object b) { - return time_cmp (a, b) == 0 ? Qt : Qnil; + /* A nil arg compares unequal to a non-nil arg. This also saves the + expense of current_timespec if either arg is nil. */ + return NILP (a) == NILP (b) && time_cmp (a, b) == 0 ? Qt : Qnil; } -- 2.39.2