[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master d75e2c12eb 1/2: Support (encode-time (list s m h D M Y))
From: |
Paul Eggert |
Subject: |
master d75e2c12eb 1/2: Support (encode-time (list s m h D M Y)) |
Date: |
Mon, 25 Apr 2022 15:40:29 -0400 (EDT) |
branch: master
commit d75e2c12ebbc7a758d1c24d30685e790b703eb64
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>
Support (encode-time (list s m h D M Y))
* src/timefns.c (Fencode_time): Add support for a 6-elt list arg.
Requested by Max Nikulin for Org (bug#54764).
* test/src/timefns-tests.el (encode-time-alternate-apis): New test.
---
doc/lispref/os.texi | 5 +++++
etc/NEWS | 5 +++++
src/timefns.c | 21 +++++++++++++++------
test/src/timefns-tests.el | 9 +++++++++
4 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 71df402a6c..af9ad0a533 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1660,6 +1660,11 @@ standard time from 4 to 3 hours east of Greenwich; if
you need to
handle situations like this you can use a numeric @var{zone} to
disambiguate instead.
+The first argument can also be a list @code{(@var{second} @var{minute}
+@var{hour} @var{day} @var{month} @var{year})}, which is treated like
+the list @code{(@var{second} @var{minute} @var{hour} @var{day}
+@var{month} @var{year} nil -1 nil)}.
+
As an obsolescent calling convention, this function can be given six
or more arguments. The first six arguments @var{second},
@var{minute}, @var{hour}, @var{day}, @var{month}, and @var{year}
diff --git a/etc/NEWS b/etc/NEWS
index 89a8c34df9..05c636102d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2011,6 +2011,11 @@ For example, '(time-add nil '(1 . 1000))' no longer
warns that the
'(1 . 1000)' acts like '(1000 . 1000000)'. This warning, which was a
temporary transition aid for Emacs 27, has served its purpose.
++++
+** 'encode-time' now also accepts a 6-element list with just time and date.
+(encode-time (list SECOND MINUTE HOUR DAY MONTH YEAR)) is now short for
+(encode-time (list SECOND MINUTE HOUR DAY MONTH YEAR nil -1 nil)).
+
+++
** 'date-to-time' now assumes earliest values if its argument lacks
month, day, or time. For example, (date-to-time "2021-12-04") now
diff --git a/src/timefns.c b/src/timefns.c
index 7a4a7075ed..b0b84a438c 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1620,6 +1620,9 @@ time zone with daylight-saving transitions, DST is t for
daylight
saving time, nil for standard time, and -1 to cause the daylight
saving flag to be guessed.
+TIME can also be a list (SECOND MINUTE HOUR DAY MONTH YEAR), which is
+equivalent to (SECOND MINUTE HOUR DAY MONTH YEAR nil -1 nil).
+
As an obsolescent calling convention, if this function is called with
6 or more arguments, the first 6 arguments are SECOND, MINUTE, HOUR,
DAY, MONTH, and YEAR, and specify the components of a decoded time.
@@ -1645,7 +1648,7 @@ usage: (encode-time TIME &rest OBSOLESCENT-ARGUMENTS) */)
if (nargs == 1)
{
Lisp_Object tail = a;
- for (int i = 0; i < 9; i++, tail = XCDR (tail))
+ for (int i = 0; i < 6; i++, tail = XCDR (tail))
CHECK_CONS (tail);
secarg = XCAR (a); a = XCDR (a);
minarg = XCAR (a); a = XCDR (a);
@@ -1653,11 +1656,17 @@ usage: (encode-time TIME &rest OBSOLESCENT-ARGUMENTS)
*/)
mdayarg = XCAR (a); a = XCDR (a);
monarg = XCAR (a); a = XCDR (a);
yeararg = XCAR (a); a = XCDR (a);
- a = XCDR (a);
- Lisp_Object dstflag = XCAR (a); a = XCDR (a);
- zone = XCAR (a);
- if (SYMBOLP (dstflag) && !FIXNUMP (zone) && !CONSP (zone))
- tm.tm_isdst = !NILP (dstflag);
+ if (! NILP (a))
+ {
+ CHECK_CONS (a);
+ a = XCDR (a);
+ CHECK_CONS (a);
+ Lisp_Object dstflag = XCAR (a); a = XCDR (a);
+ CHECK_CONS (a);
+ zone = XCAR (a);
+ if (SYMBOLP (dstflag) && !FIXNUMP (zone) && !CONSP (zone))
+ tm.tm_isdst = !NILP (dstflag);
+ }
}
else if (nargs < 6)
xsignal2 (Qwrong_number_of_arguments, Qencode_time, make_fixnum (nargs));
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el
index e7c464472d..08d06f27d9 100644
--- a/test/src/timefns-tests.el
+++ b/test/src/timefns-tests.el
@@ -225,6 +225,15 @@ a fixed place on the right and are padded on the left."
(encode-time '(29 31 17 30 4 2019 2 t 7200))
'(23752 27217))))
+(ert-deftest encode-time-alternate-apis ()
+ (let* ((time '(30 30 12 15 6 1970))
+ (time-1 (append time '(nil -1 nil)))
+ (etime (encode-time time)))
+ (should (time-equal-p etime (encode-time time-1)))
+ (should (time-equal-p etime (apply #'encode-time time)))
+ (should (time-equal-p etime (apply #'encode-time time-1)))
+ (should (time-equal-p etime (apply #'encode-time (append time '(nil)))))))
+
(ert-deftest float-time-precision ()
(should (= (float-time '(0 1 0 4025)) 1.000000004025))
(should (= (float-time '(1000000004025 . 1000000000000)) 1.000000004025))