[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.
+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;
}
- master afa67ed6f2 08/16: Fix year-285428751 bug in hanoi-unix-64, (continued)
- master afa67ed6f2 08/16: Fix year-285428751 bug in hanoi-unix-64, Paul Eggert, 2022/08/01
- master 353413a76b 10/16: * lisp/vc/vc.el: Remove stray comment hyphen., Paul Eggert, 2022/08/01
- master 932c0bc1fc 01/16: Tune blv_found, Paul Eggert, 2022/08/01
- master d6c054a007 09/16: Fix "cons up a storm" issue in type-break, Paul Eggert, 2022/08/01
- master a51863f73d 12/16: Simplify a few timestamps, Paul Eggert, 2022/08/01
- master d634cb0954 11/16: Omit some (current-time) calls, Paul Eggert, 2022/08/01
- master 2cd204d8bb 13/16: Prefer ‘time-equal-p’ to ‘equal’ on timestamps, Paul Eggert, 2022/08/01
- master 72c3efd7d0 15/16: Fix time comparison in primitive-undo, Paul Eggert, 2022/08/01
- master bec8474a45 16/16: Improve GCC pacification in xterm.c, Paul Eggert, 2022/08/01
- master 0a4477415c 05/16: Improve float-time etc. performance, Paul Eggert, 2022/08/01
- master 9d4633e934 02/16: (time-equal-p nil X) returns nil,
Paul Eggert <=
- master e3b6242938 03/16: Fix get-internal-runtime precision, Paul Eggert, 2022/08/01
- master 2fd2008e67 07/16: * src/timefns.c (Ffloat_time): Fix doc string., Paul Eggert, 2022/08/01
- master 4d896c0977 14/16: Use list-form timestamps in .nnmh-articles, Paul Eggert, 2022/08/01