[Top][All Lists]

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

master 9d4633e934 02/16: (time-equal-p nil X) returns nil

From: Paul Eggert
Subject: master 9d4633e934 02/16: (time-equal-p nil X) returns nil
Date: Mon, 1 Aug 2022 04:17:27 -0400 (EDT)

branch: master
commit 9d4633e934da77bc1c3617a9450ee17151f35271
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>

    (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 2b49818ed3..5fb34fb9b6 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.  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 9df50eaecc..25bfda513c 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;

reply via email to

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