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.
This commit is contained in:
parent
fd1ca094bc
commit
d75e2c12eb
4 changed files with 34 additions and 6 deletions
|
@ -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}
|
||||
|
|
5
etc/NEWS
5
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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue