summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-04-25 11:56:48 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2022-04-25 12:40:20 -0700
commitd75e2c12ebbc7a758d1c24d30685e790b703eb64 (patch)
tree8c5cd9c875ca7f3d4eb37fe6e94a1db8a1759f15
parentfd1ca094bc43d8fab859e7b78280f9f9693105f1 (diff)
downloademacs-d75e2c12ebbc7a758d1c24d30685e790b703eb64.tar.gz
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.
-rw-r--r--doc/lispref/os.texi5
-rw-r--r--etc/NEWS5
-rw-r--r--src/timefns.c21
-rw-r--r--test/src/timefns-tests.el9
4 files changed, 34 insertions, 6 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 71df402a6cb..af9ad0a533c 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 89a8c34df91..05c636102d8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2012,6 +2012,11 @@ For example, '(time-add nil '(1 . 1000))' no longer warns that the
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
assumes a time of 00:00 instead of signaling an error.
diff --git a/src/timefns.c b/src/timefns.c
index 7a4a7075edc..b0b84a438ce 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 e7c464472d0..08d06f27d9e 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))