New function time-convert
This replaces the awkward reuse of encode-time to both convert calendrical timestamps to Lisp timestamps, and to convert Lisp timestamps to other forms. Now, encode-time does just the former and the new function does just the latter. The new function builds on a suggestion by Lars Ingebrigtsen in: https://lists.gnu.org/r/emacs-devel/2019-07/msg00801.html and refined by Stefan Monnier in: https://lists.gnu.org/r/emacs-devel/2019-07/msg00803.html * doc/lispref/os.texi (Time of Day, Time Conversion): * doc/misc/emacs-mime.texi (time-date): * etc/NEWS: Update documentation. * lisp/calendar/cal-dst.el (calendar-next-time-zone-transition): * lisp/calendar/time-date.el (seconds-to-time, days-to-time): * lisp/calendar/timeclock.el (timeclock-seconds-to-time): * lisp/cedet/ede/detect.el (ede-detect-qtest): * lisp/completion.el (cmpl-hours-since-origin): * lisp/ecomplete.el (ecomplete-add-item): * lisp/emacs-lisp/cl-extra.el (cl--random-time): * lisp/emacs-lisp/timer.el (timer--time-setter) (timer-next-integral-multiple-of-time): * lisp/find-lisp.el (find-lisp-format-time): * lisp/gnus/gnus-diary.el (gnus-user-format-function-d): * lisp/gnus/gnus-group.el (gnus-group-set-timestamp): * lisp/gnus/gnus-icalendar.el (gnus-icalendar-show-org-agenda): * lisp/gnus/nnrss.el (nnrss-normalize-date): * lisp/gnus/nnspool.el (nnspool-request-newgroups): * lisp/net/ntlm.el (ntlm-compute-timestamp): * lisp/net/pop3.el (pop3-uidl-dele): * lisp/obsolete/vc-arch.el (vc-arch-add-tagline): * lisp/org/org-clock.el (org-clock-get-clocked-time) (org-clock-resolve, org-resolve-clocks, org-clock-in) (org-clock-out, org-clock-sum): * lisp/org/org-id.el (org-id-uuid, org-id-time-to-b36): * lisp/org/ox-publish.el (org-publish-cache-ctime-of-src): * lisp/proced.el (proced-format-time): * lisp/progmodes/cc-cmds.el (c-progress-init) (c-progress-update): * lisp/progmodes/cperl-mode.el (cperl-time-fontification): * lisp/progmodes/flymake.el (flymake--schedule-timer-maybe): * lisp/progmodes/vhdl-mode.el (vhdl-update-progress-info) (vhdl-fix-case-region-1): * lisp/tar-mode.el (tar-octal-time): * lisp/time.el (emacs-uptime): * lisp/url/url-auth.el (url-digest-auth-make-cnonce): * lisp/url/url-util.el (url-lazy-message): * lisp/vc/vc-cvs.el (vc-cvs-parse-entry): * lisp/vc/vc-hg.el (vc-hg-state-fast): * lisp/xt-mouse.el (xterm-mouse-event): * test/lisp/emacs-lisp/timer-tests.el: (timer-next-integral-multiple-of-time-2): Use time-convert, not encode-time. * lisp/calendar/icalendar.el (icalendar--decode-isodatetime): Don’t use now-removed FORM argument for encode-time. It wasn’t crucial anyway. * lisp/emacs-lisp/byte-opt.el (side-effect-free-fns): Add time-convert. * lisp/emacs-lisp/elint.el (elint-unknown-builtin-args): Update encode-time signature to match current arg set. * lisp/emacs-lisp/timer.el (timer-next-integral-multiple-of-time): Use timer-convert with t rather than doing it by hand. * src/timefns.c (time_hz_ticks, time_form_stamp, lisp_time_form_stamp): Remove; no longer needed. (decode_lisp_time): Rturn the form instead of having a *PFORM arg. All uses changed. (time_arith): Just return TICKS if HZ is 1. (Fencode_time): Remove argument FORM. All callers changed. Do not attempt to encode time values; just encode decoded (calendrical) times. Unless CURRENT_TIME_LIST, just return VALUE since HZ is 1. (Ftime_convert): New function, which does the time value conversion that bleeding-edge encode-time formerly did. Return TIME if it is easy to see that it is already of the correct form. (Fcurrent_time): Mention in doc that the form is planned to change. * test/src/timefns-tests.el (decode-then-encode-time): Don’t use (encode-time nil).
This commit is contained in:
parent
c6ba8100ea
commit
89c63b3522
42 changed files with 219 additions and 216 deletions
|
@ -1536,10 +1536,8 @@ Operating System Interface
|
|||
* System Environment:: Distinguish the name and kind of system.
|
||||
* User Identification:: Finding the name and user id of the user.
|
||||
* Time of Day:: Getting the current time.
|
||||
* Time Conversion:: Converting a time from numeric form to
|
||||
calendrical data and vice versa.
|
||||
* Time Parsing:: Converting a time from numeric form to text
|
||||
and vice versa.
|
||||
* Time Conversion:: Converting among timestamp forms.
|
||||
* Time Parsing:: Converting timestamps to text and vice versa.
|
||||
* Processor Run Time:: Getting the run time used by Emacs.
|
||||
* Time Calculations:: Adding, subtracting, comparing times, etc.
|
||||
* Timers:: Setting a timer to call a function at a
|
||||
|
|
|
@ -20,10 +20,8 @@ terminal and the screen.
|
|||
* User Identification:: Finding the name and user id of the user.
|
||||
* Time of Day:: Getting the current time.
|
||||
* Time Zone Rules:: Rules for time zones and daylight saving time.
|
||||
* Time Conversion:: Converting a time from numeric form to
|
||||
calendrical data and vice versa.
|
||||
* Time Parsing:: Converting a time from numeric form to text
|
||||
and vice versa.
|
||||
* Time Conversion:: Converting among timestamp forms.
|
||||
* Time Parsing:: Converting timestamps to text and vice versa.
|
||||
* Processor Run Time:: Getting the run time used by Emacs.
|
||||
* Time Calculations:: Adding, subtracting, comparing times, etc.
|
||||
* Timers:: Setting a timer to call a function at a certain time.
|
||||
|
@ -1253,7 +1251,7 @@ represent absolute time by counting seconds since the @dfn{epoch} of
|
|||
Although traditionally Lisp timestamps were integer pairs, their
|
||||
form has evolved and programs ordinarily should not depend on the
|
||||
current default form. If your program needs a particular timestamp
|
||||
form, you can use the @code{encode-time} function to convert it to the
|
||||
form, you can use the @code{time-convert} function to convert it to the
|
||||
needed form. @xref{Time Conversion}.
|
||||
|
||||
@cindex epoch
|
||||
|
@ -1304,7 +1302,7 @@ time, a single floating-point number for seconds, or a list
|
|||
@var{low})} that is a truncated list timestamp with missing elements
|
||||
taken to be zero. You can convert a time value into
|
||||
a human-readable string using @code{format-time-string}, into a Lisp
|
||||
timestamp using @code{encode-time}, and into other forms using
|
||||
timestamp using @code{time-convert}, and into other forms using
|
||||
@code{decode-time} and @code{float-time}. These functions are
|
||||
described in the following sections.
|
||||
|
||||
|
@ -1334,6 +1332,11 @@ defaults to the current time zone rule. @xref{Time Zone Rules}.
|
|||
|
||||
@defun current-time
|
||||
This function returns the current time as a Lisp timestamp.
|
||||
Although the timestamp takes the form @code{(@var{high} @var{low}
|
||||
@var{micro} @var{pico})} in the current Emacs release, this is
|
||||
planned to change in a future Emacs version. You can use the
|
||||
@code{time-convert} function to convert a timestamp to some other
|
||||
form. @xref{Time Conversion}.
|
||||
@end defun
|
||||
|
||||
@defun float-time &optional time
|
||||
|
@ -1411,8 +1414,8 @@ defaults to the current time zone rule.
|
|||
@cindex calendrical information
|
||||
@cindex time conversion
|
||||
|
||||
These functions convert time values (@pxref{Time of Day}) into
|
||||
calendrical information and vice versa.
|
||||
These functions convert time values (@pxref{Time of Day}) to Lisp
|
||||
timestamps, or into calendrical information and vice versa.
|
||||
|
||||
Many 32-bit operating systems are limited to system times containing
|
||||
32 bits of information in their seconds component; these systems
|
||||
|
@ -1421,12 +1424,60 @@ typically handle only the times from 1901-12-13 20:45:52 through
|
|||
systems have larger seconds components, and can represent times far in
|
||||
the past or future.
|
||||
|
||||
Time conversion functions always use the Gregorian calendar, even
|
||||
Calendrical conversion functions always use the Gregorian calendar, even
|
||||
for dates before the Gregorian calendar was introduced. Year numbers
|
||||
count the number of years since the year 1 B.C., and do not skip zero
|
||||
as traditional Gregorian years do; for example, the year number
|
||||
@minus{}37 represents the Gregorian year 38 B.C@.
|
||||
|
||||
@defun time-convert time &optional form
|
||||
This function converts a time value into a Lisp timestamp.
|
||||
If the time cannot be represented exactly, it is truncated
|
||||
toward minus infinity.
|
||||
|
||||
The optional @var{form} argument specifies the timestamp form to be
|
||||
returned. If @var{form} is the symbol @code{integer}, this function
|
||||
returns an integer count of seconds. If @var{form} is a positive
|
||||
integer, it specifies a clock frequency and this function returns an
|
||||
integer-pair timestamp @code{(@var{ticks}
|
||||
. @var{form})}.@footnote{Currently a positive integer @var{form}
|
||||
should be at least 65536 if the returned value is intended to be given
|
||||
to standard functions expecting Lisp timestamps.} If @var{form} is
|
||||
@code{t}, this function treats it as a positive integer suitable for
|
||||
representing the timestamp; for example, it is treated as 1000000000
|
||||
if @var{time} is nil and the platform timestamp has nanosecond
|
||||
resolution. If @var{form} is @code{list}, this function returns an
|
||||
integer list @code{(@var{high} @var{low} @var{micro} @var{pico})}.
|
||||
Although an omitted or @code{nil} @var{form} currently acts like
|
||||
@code{list}, this is planned to change in a future Emacs version, so
|
||||
callers requiring list timestamps should pass @code{list} explicitly.
|
||||
|
||||
If @var{time} already has the proper form, this function might yield
|
||||
@var{time} rather than a copy.
|
||||
|
||||
Although @code{(time-convert nil nil)} is equivalent to
|
||||
@code{(current-time)}, the latter may be a bit faster.
|
||||
|
||||
@example
|
||||
@group
|
||||
(setq a (time-convert nil t))
|
||||
@result{} (1564826753904873156 . 1000000000)
|
||||
@end group
|
||||
@group
|
||||
(time-convert a 100000)
|
||||
@result{} (156482675390487 . 100000)
|
||||
@end group
|
||||
@group
|
||||
(time-convert a 'integer)
|
||||
@result{} 1564826753
|
||||
@end group
|
||||
@group
|
||||
(time-convert a 'list)
|
||||
@result{} (23877 23681 904873 156000)
|
||||
@end group
|
||||
@end example
|
||||
@end defun
|
||||
|
||||
@defun decode-time &optional time zone
|
||||
This function converts a time value into calendrical information. If
|
||||
you don't specify @var{time}, it decodes the current time, and similarly
|
||||
|
@ -1522,37 +1573,17 @@ that represents ``two months'', you could say:
|
|||
@end lisp
|
||||
@end defun
|
||||
|
||||
@defun encode-time &optional time form &rest obsolescent-arguments
|
||||
@defun encode-time time &rest obsolescent-arguments
|
||||
This function converts @var{time} to a Lisp timestamp.
|
||||
It can act as the inverse of @code{decode-time}.
|
||||
|
||||
The first argument can be a time value such as a number of seconds, a
|
||||
pair @code{(@var{ticks} . @var{hz})}, a list @code{(@var{high}
|
||||
@var{low} @var{micro} @var{pico})}, or @code{nil} (the default) for
|
||||
the current time (@pxref{Time of Day}). It can also be a list
|
||||
Ordinarily the first argument is a list
|
||||
@code{(@var{second} @var{minute} @var{hour} @var{day} @var{month}
|
||||
@var{year} @var{ignored} @var{dst} @var{zone})} that specifies a
|
||||
decoded time in the style of @code{decode-time}, so that
|
||||
@code{(encode-time (decode-time ...))} works. For the meanings of
|
||||
these list members, see the table under @code{decode-time}.
|
||||
|
||||
The optional @var{form} argument specifies the desired timestamp form
|
||||
to be returned. If @var{form} is the symbol @code{integer}, this
|
||||
function returns an integer count of seconds. If @var{form} is a
|
||||
positive integer, it specifies a clock frequency and this function
|
||||
returns an integer-pair timestamp @code{(@var{ticks}
|
||||
. @var{form})}.@footnote{Currently a positive integer @var{form}
|
||||
should be at least 65536 if the returned value is intended to be given
|
||||
to standard functions expecting Lisp timestamps.} If @var{form} is
|
||||
@code{t}, this function treats it as a positive integer suitable for
|
||||
representing the timestamp; for example, it is treated as 1000000000
|
||||
if the platform timestamp has nanosecond resolution. If @var{form} is
|
||||
@code{list}, this function returns an integer list @code{(@var{high}
|
||||
@var{low} @var{micro} @var{pico})}. Although an omitted or @code{nil}
|
||||
@var{form} currently acts like @code{list}, this is planned to change
|
||||
in a future Emacs version, so callers requiring list timestamps should
|
||||
pass @code{list} explicitly.
|
||||
|
||||
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}
|
||||
|
|
|
@ -1537,24 +1537,25 @@ Here's a bunch of time/date/second/day examples:
|
|||
(parse-time-string "Sat Sep 12 12:21:54 1998 +0200")
|
||||
@result{} (54 21 12 12 9 1998 6 -1 7200)
|
||||
|
||||
(encode-time (date-to-time "Sat Sep 12 12:21:54 1998 +0200")
|
||||
1000000)
|
||||
@result{} (905595714000000 . 1000000)
|
||||
(time-convert
|
||||
(date-to-time "Sat Sep 12 12:21:54 1998 +0200")
|
||||
'integer)
|
||||
@result{} 905595714
|
||||
|
||||
(float-time '(905595714000000 . 1000000))
|
||||
@result{} 905595714.0
|
||||
|
||||
(encode-time 905595714.0 1000000)
|
||||
(time-convert 905595714.0 1000000)
|
||||
@result{} (905595714000000 . 1000000)
|
||||
|
||||
(time-to-days '(905595714000000 . 1000000))
|
||||
@result{} 729644
|
||||
|
||||
(encode-time (days-to-time 729644) 1000000)
|
||||
@result{} (63041241600000000 . 1000000)
|
||||
(time-convert (days-to-time 729644) 'integer)
|
||||
@result{} 63041241600
|
||||
|
||||
(encode-time (time-since '(905595714000000 . 1000000))
|
||||
1000000)
|
||||
(time-convert (time-since '(905595714000000 . 1000000))
|
||||
1000000)
|
||||
@result{} (631963244775642171 . 1000000000)
|
||||
|
||||
(time-less-p '(905595714000000 . 1000000)
|
||||
|
@ -1622,12 +1623,14 @@ These are the functions available:
|
|||
@item date-to-time
|
||||
Take a date and return a time.
|
||||
|
||||
@item time-convert
|
||||
Take a time and return a timestamp in a specified form.
|
||||
|
||||
@item float-time
|
||||
Take a time and return seconds.
|
||||
|
||||
@item encode-time
|
||||
Take seconds (and other ways to represent time, notably decoded time
|
||||
lists), and return a time.
|
||||
Take a decoded time and return a timestamp.
|
||||
|
||||
@item time-to-days
|
||||
Take a time and return days.
|
||||
|
|
15
etc/NEWS
15
etc/NEWS
|
@ -2077,21 +2077,24 @@ functions like 'process-id' that compute process IDs, and functions like
|
|||
|
||||
** Time values
|
||||
|
||||
+++
|
||||
*** New function time 'time-convert' converts Lisp time values
|
||||
to Lisp timestamps of various forms, including a new timestamp form
|
||||
(TICKS . HZ) where TICKS is an integer and HZ a positive integer
|
||||
denoting a clock frequency.
|
||||
|
||||
+++
|
||||
*** Although the default timestamp format is still '(HI LO US PS)',
|
||||
it is planned to change in a future Emacs version, to exploit bignums.
|
||||
The documentation has been updated to mention that the timestamp
|
||||
format may change and that programs should use functions like
|
||||
'format-time-string', 'decode-time', and 'encode-time' rather than
|
||||
'format-time-string', 'decode-time', and 'time-convert' rather than
|
||||
probing the innards of a timestamp directly, or creating a timestamp
|
||||
by hand.
|
||||
|
||||
+++
|
||||
*** 'encode-time' supports a new API '(encode-time TIME &optional FORM)'.
|
||||
This can convert decoded times and Lisp time values to Lisp timestamps
|
||||
of various forms, including a new timestamp form '(TICKS . HZ)', where
|
||||
TICKS is an integer and HZ is a positive integer denoting a clock
|
||||
frequency. The old 'encode-time' API is still supported.
|
||||
*** 'encode-time' supports a new API '(encode-time TIME)'.
|
||||
The old 'encode-time' API is still supported.
|
||||
|
||||
+++
|
||||
*** A new package to parse ISO 8601 time, date, durations and
|
||||
|
|
|
@ -127,7 +127,7 @@ after midnight UTC on absolute date ABS-DATE."
|
|||
"Return the time of the next time zone transition after TIME.
|
||||
Both TIME and the result are acceptable arguments to `current-time-zone'.
|
||||
Return nil if no such transition can be found."
|
||||
(let* ((time (encode-time time 'integer))
|
||||
(let* ((time (time-convert time 'integer))
|
||||
(time-zone (current-time-zone time))
|
||||
(time-utc-diff (car time-zone))
|
||||
hi
|
||||
|
|
|
@ -646,7 +646,7 @@ FIXME: multiple comma-separated values should be allowed!"
|
|||
(let ((decoded-time (list second minute hour day month year
|
||||
nil -1 zone)))
|
||||
(condition-case nil
|
||||
(decode-time (encode-time decoded-time 'integer))
|
||||
(decode-time (encode-time decoded-time))
|
||||
(error
|
||||
(message "Cannot decode \"%s\"" isodatetimestring)
|
||||
;; Hope for the best....
|
||||
|
|
|
@ -171,14 +171,14 @@ If DATE lacks timezone information, GMT is assumed."
|
|||
(defalias 'time-to-seconds 'float-time)
|
||||
|
||||
;;;###autoload
|
||||
(defalias 'seconds-to-time 'encode-time)
|
||||
(defalias 'seconds-to-time 'time-convert)
|
||||
|
||||
;;;###autoload
|
||||
(defun days-to-time (days)
|
||||
"Convert DAYS into a time value."
|
||||
(let ((time (encode-time (* 86400 days))))
|
||||
(let ((time (time-convert (* 86400 days))))
|
||||
;; Traditionally, this returned a two-element list if DAYS was an integer.
|
||||
;; Keep that tradition if encode-time outputs timestamps in list form.
|
||||
;; Keep that tradition if time-convert outputs timestamps in list form.
|
||||
(if (and (integerp days) (consp (cdr time)))
|
||||
(setcdr (cdr time) nil))
|
||||
time))
|
||||
|
|
|
@ -515,7 +515,7 @@ non-nil, the amount returned will be relative to past time worked."
|
|||
string)))
|
||||
|
||||
(define-obsolete-function-alias 'timeclock-time-to-seconds 'float-time "26.1")
|
||||
(define-obsolete-function-alias 'timeclock-seconds-to-time 'encode-time "26.1")
|
||||
(define-obsolete-function-alias 'timeclock-seconds-to-time 'time-convert "26.1")
|
||||
|
||||
;; Should today-only be removed in favor of timeclock-relative? - gm
|
||||
(defsubst timeclock-when-to-leave (&optional today-only)
|
||||
|
|
|
@ -200,7 +200,7 @@ Return a cons cell:
|
|||
(ans (ede-detect-directory-for-project default-directory)))
|
||||
(if ans
|
||||
(message "Project found in %d sec @ %s of type %s"
|
||||
(encode-time (time-since start) 'integer)
|
||||
(time-convert (time-since start) 'integer)
|
||||
(car ans)
|
||||
(eieio-object-name-string (cdr ans)))
|
||||
(message "No Project found.") )))
|
||||
|
|
|
@ -432,7 +432,7 @@ Used to decide whether to save completions.")
|
|||
|
||||
|
||||
(defun cmpl-hours-since-origin ()
|
||||
(floor (encode-time nil 'integer) 3600))
|
||||
(floor (time-convert nil 'integer) 3600))
|
||||
|
||||
;;---------------------------------------------------------------------------
|
||||
;; "Symbol" parsing functions
|
||||
|
|
|
@ -96,7 +96,7 @@ string that was matched."
|
|||
(defun ecomplete-add-item (type key text)
|
||||
"Add item TEXT of TYPE to the database, using KEY as the identifier."
|
||||
(let ((elems (assq type ecomplete-database))
|
||||
(now (encode-time nil 'integer))
|
||||
(now (time-convert nil 'integer))
|
||||
entry)
|
||||
(unless elems
|
||||
(push (setq elems (list type)) ecomplete-database))
|
||||
|
|
|
@ -1234,7 +1234,7 @@
|
|||
symbol-function symbol-name symbol-plist symbol-value string-make-unibyte
|
||||
string-make-multibyte string-as-multibyte string-as-unibyte
|
||||
string-to-multibyte
|
||||
tan truncate
|
||||
tan time-convert truncate
|
||||
unibyte-char-to-multibyte upcase user-full-name
|
||||
user-login-name user-original-login-name custom-variable-p
|
||||
vconcat
|
||||
|
|
|
@ -437,7 +437,7 @@ as an integer unless JUNK-ALLOWED is non-nil."
|
|||
;; Random numbers.
|
||||
|
||||
(defun cl--random-time ()
|
||||
(car (encode-time nil t)))
|
||||
(car (time-convert nil t)))
|
||||
|
||||
;;;###autoload (autoload 'cl-random-state-p "cl-extra")
|
||||
(cl-defstruct (cl--random-state
|
||||
|
|
|
@ -141,7 +141,7 @@ Set by `elint-initialize', if `elint-scan-preloaded' is non-nil.")
|
|||
(defconst elint-unknown-builtin-args
|
||||
;; encode-time allows extra arguments for use with decode-time.
|
||||
;; For some reason, some people seem to like to use them in other cases.
|
||||
'((encode-time second minute hour day month year &rest zone))
|
||||
'((encode-time time &rest obsolescent-arguments))
|
||||
"Those built-ins for which we can't find arguments, if any.")
|
||||
|
||||
(defvar elint-extra-errors '(file-locked file-supersession ftp-error)
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
|
||||
(defun timer--time-setter (timer time)
|
||||
(timer--check timer)
|
||||
(let ((lt (encode-time time 'list)))
|
||||
(let ((lt (time-convert time 'list)))
|
||||
(setf (timer--high-seconds timer) (nth 0 lt))
|
||||
(setf (timer--low-seconds timer) (nth 1 lt))
|
||||
(setf (timer--usecs timer) (nth 2 lt))
|
||||
|
@ -96,10 +96,7 @@ fire each time Emacs is idle for that many seconds."
|
|||
"Yield the next value after TIME that is an integral multiple of SECS.
|
||||
More precisely, the next value, after TIME, that is an integral multiple
|
||||
of SECS seconds since the epoch. SECS may be a fraction."
|
||||
(let* ((ticks-hz (if (and (consp time) (integerp (car time))
|
||||
(integerp (cdr time)) (< 0 (cdr time)))
|
||||
time
|
||||
(encode-time time 1000000000000)))
|
||||
(let* ((ticks-hz (time-convert time t))
|
||||
(ticks (car ticks-hz))
|
||||
(hz (cdr ticks-hz))
|
||||
trunc-s-ticks)
|
||||
|
@ -109,7 +106,7 @@ of SECS seconds since the epoch. SECS may be a fraction."
|
|||
(setq ticks (ash ticks 1))
|
||||
(setq hz (ash hz 1)))
|
||||
(let ((more-ticks (+ ticks trunc-s-ticks)))
|
||||
(encode-time (cons (- more-ticks (% more-ticks trunc-s-ticks)) hz)))))
|
||||
(time-convert (cons (- more-ticks (% more-ticks trunc-s-ticks)) hz)))))
|
||||
|
||||
(defun timer-relative-time (time secs &optional usecs psecs)
|
||||
"Advance TIME by SECS seconds and optionally USECS microseconds
|
||||
|
|
|
@ -342,7 +342,7 @@ list of ls option letters of which c and u are recognized). Use
|
|||
the same method as \"ls\" to decide whether to show time-of-day or
|
||||
year, depending on distance between file date and NOW."
|
||||
(let* ((time (nth (find-lisp-time-index switches) file-attr))
|
||||
(diff (encode-time (time-subtract time now) 'integer))
|
||||
(diff (time-convert (time-subtract time now) 'integer))
|
||||
(past-cutoff -15778476) ; 1/2 of a Gregorian year
|
||||
(future-cutoff (* 60 60))) ; 1 hour
|
||||
(format-time-string
|
||||
|
|
|
@ -161,7 +161,7 @@ There are currently two built-in format functions:
|
|||
(now (current-time))
|
||||
(occur (nndiary-next-occurrence sched now))
|
||||
(real-time (time-subtract occur now)))
|
||||
(let* ((sec (encode-time real-time 'integer))
|
||||
(let* ((sec (time-convert real-time 'integer))
|
||||
(past (< sec 0))
|
||||
delay)
|
||||
(and past (setq sec (- sec)))
|
||||
|
|
|
@ -4533,7 +4533,7 @@ and the second element is the address."
|
|||
This function can be used in hooks like `gnus-select-group-hook'
|
||||
or `gnus-group-catchup-group-hook'."
|
||||
(when gnus-newsgroup-name
|
||||
(let ((time (encode-time nil 'integer)))
|
||||
(let ((time (time-convert nil 'integer)))
|
||||
(gnus-group-set-parameter gnus-newsgroup-name 'timestamp time))))
|
||||
|
||||
(defsubst gnus-group-timestamp (group)
|
||||
|
|
|
@ -650,7 +650,7 @@ is searched."
|
|||
(defun gnus-icalendar-show-org-agenda (event)
|
||||
(let* ((time-delta (time-subtract (gnus-icalendar-event:end-time event)
|
||||
(gnus-icalendar-event:start-time event)))
|
||||
(duration-days (1+ (floor (encode-time time-delta 'integer) 86400))))
|
||||
(duration-days (1+ (floor (time-convert time-delta 'integer) 86400))))
|
||||
(org-agenda-list nil (gnus-icalendar-event:start event) duration-days)))
|
||||
|
||||
(cl-defmethod gnus-icalendar-event:sync-to-org ((event gnus-icalendar-event-request) reply-status)
|
||||
|
|
|
@ -455,7 +455,7 @@ which RSS 2.0 allows."
|
|||
(cond ((null date)) ; do nothing for this case
|
||||
;; if the date is just digits (unix time stamp):
|
||||
((string-match "^[0-9]+$" date)
|
||||
(setq given (encode-time (string-to-number date))))
|
||||
(setq given (time-convert (string-to-number date))))
|
||||
;; RFC 822
|
||||
((string-match " [0-9]+ " date)
|
||||
(setq vector (timezone-parse-date date)
|
||||
|
|
|
@ -305,7 +305,7 @@ there.")
|
|||
(while (and (not (looking-at
|
||||
"\\([^ ]+\\) +\\([0-9]+\\)[0-9][0-9][0-9] "))
|
||||
(zerop (forward-line -1))))
|
||||
(let ((seconds (encode-time (date-to-time date) 'integer))
|
||||
(let ((seconds (time-convert (date-to-time date) 'integer))
|
||||
groups)
|
||||
;; Go through lines and add the latest groups to a list.
|
||||
(while (and (looking-at "\\([^ ]+\\) +[0-9]+ ")
|
||||
|
|
|
@ -151,7 +151,7 @@ signed integer."
|
|||
;; tenths of microseconds between
|
||||
;; 1601-01-01 and 1970-01-01
|
||||
"116444736000000000)")
|
||||
'rawnum (encode-time nil 'list)))
|
||||
'rawnum (time-convert nil 'list)))
|
||||
result-bytes)
|
||||
(dotimes (_byte 8)
|
||||
(push (calc-eval "and($1,16#FF)" 'rawnum tenths-of-us-since-jan-1-1601)
|
||||
|
|
|
@ -379,7 +379,7 @@ Use streaming commands."
|
|||
(defun pop3-uidl-dele (process)
|
||||
"Delete messages according to `pop3-leave-mail-on-server'.
|
||||
Return non-nil if it is necessary to update the local UIDL file."
|
||||
(let* ((ctime (encode-time nil 'list))
|
||||
(let* ((ctime (time-convert nil 'list))
|
||||
(age-limit (and (numberp pop3-leave-mail-on-server)
|
||||
(* 86400 pop3-leave-mail-on-server)))
|
||||
(srvr (assoc pop3-mailhost pop3-uidl-saved))
|
||||
|
|
|
@ -133,7 +133,7 @@ If nil, use the value of `vc-diff-switches'. If t, use no switches."
|
|||
(file-error (insert (format "%s <%s> %s"
|
||||
(current-time-string)
|
||||
user-mail-address
|
||||
(+ (% (car (encode-time nil 1000000))
|
||||
(+ (% (car (time-convert nil 1000000))
|
||||
1000000)
|
||||
(buffer-size)))))))
|
||||
(comment-region beg (point))))
|
||||
|
|
|
@ -723,7 +723,7 @@ menu\nmouse-2 will jump to task"))
|
|||
The time returned includes the time spent on this task in
|
||||
previous clocking intervals."
|
||||
(let ((currently-clocked-time
|
||||
(floor (encode-time (time-since org-clock-start-time) 'integer)
|
||||
(floor (time-convert (time-since org-clock-start-time) 'integer)
|
||||
60)))
|
||||
(+ currently-clocked-time (or org-clock-total-time 0))))
|
||||
|
||||
|
@ -1033,7 +1033,7 @@ to be CLOCKED OUT."))))
|
|||
nil 45)))
|
||||
(and (not (memq char-pressed '(?i ?q))) char-pressed)))))
|
||||
(default
|
||||
(floor (encode-time (time-since last-valid) 'integer)
|
||||
(floor (time-convert (time-since last-valid) 'integer)
|
||||
60))
|
||||
(keep
|
||||
(and (memq ch '(?k ?K))
|
||||
|
@ -1102,8 +1102,8 @@ If `only-dangling-p' is non-nil, only ask to resolve dangling
|
|||
(lambda (clock)
|
||||
(format
|
||||
"Dangling clock started %d mins ago"
|
||||
(floor (encode-time (time-since (cdr clock))
|
||||
'integer)
|
||||
(floor (time-convert (time-since (cdr clock))
|
||||
'integer)
|
||||
60)))))
|
||||
(or last-valid
|
||||
(cdr clock)))))))))))
|
||||
|
@ -1321,7 +1321,7 @@ the default behavior."
|
|||
(y-or-n-p
|
||||
(format
|
||||
"You stopped another clock %d mins ago; start this one from then? "
|
||||
(/ (encode-time
|
||||
(/ (time-convert
|
||||
(time-subtract
|
||||
(org-current-time org-clock-rounding-minutes t)
|
||||
leftover)
|
||||
|
@ -1576,10 +1576,10 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
|
|||
(delete-region (point) (point-at-eol))
|
||||
(insert "--")
|
||||
(setq te (org-insert-time-stamp (or at-time now) 'with-hm 'inactive))
|
||||
(setq s (encode-time (time-subtract
|
||||
(org-time-string-to-time te)
|
||||
(org-time-string-to-time ts))
|
||||
'integer)
|
||||
(setq s (time-convert (time-subtract
|
||||
(org-time-string-to-time te)
|
||||
(org-time-string-to-time ts))
|
||||
'integer)
|
||||
h (floor s 3600)
|
||||
m (floor (mod s 3600) 60))
|
||||
(insert " => " (format "%2d:%02d" h m))
|
||||
|
@ -1833,7 +1833,7 @@ PROPNAME lets you set a custom text property instead of :org-clock-minutes."
|
|||
tend
|
||||
(>= (float-time org-clock-start-time) tstart)
|
||||
(<= (float-time org-clock-start-time) tend))
|
||||
(let ((time (floor (encode-time
|
||||
(let ((time (floor (time-convert
|
||||
(time-since org-clock-start-time)
|
||||
'integer)
|
||||
60)))
|
||||
|
|
|
@ -356,7 +356,7 @@ So a typical ID could look like \"Org:4nd91V40HI\"."
|
|||
"Return string with random (version 4) UUID."
|
||||
(let ((rnd (md5 (format "%s%s%s%s%s%s%s"
|
||||
(random)
|
||||
(encode-time nil 'list)
|
||||
(time-convert nil 'list)
|
||||
(user-uid)
|
||||
(emacs-pid)
|
||||
(user-full-name)
|
||||
|
@ -418,7 +418,7 @@ using `org-id-decode'."
|
|||
;; FIXME: If TIME represents N seconds after the epoch, then
|
||||
;; this encoding assumes 0 <= N < 110075314176 = (* (expt 36 4) 65536),
|
||||
;; i.e., that TIME is from 1970-01-01 00:00:00 to 5458-02-23 20:09:36 UTC.
|
||||
(setq time (encode-time time 'list))
|
||||
(setq time (time-convert time 'list))
|
||||
(concat (org-id-int-to-b36 (nth 0 time) 4)
|
||||
(org-id-int-to-b36 (nth 1 time) 4)
|
||||
(org-id-int-to-b36 (nth 2 time) 4)))
|
||||
|
|
|
@ -1348,7 +1348,7 @@ does not exist."
|
|||
(expand-file-name (or (file-symlink-p file) file)
|
||||
(file-name-directory file)))))
|
||||
(if (not attr) (error "No such file: \"%s\"" file)
|
||||
(encode-time (file-attribute-modification-time attr) 'integer))))
|
||||
(time-convert (file-attribute-modification-time attr) 'integer))))
|
||||
|
||||
|
||||
(provide 'ox-publish)
|
||||
|
|
|
@ -1348,7 +1348,7 @@ Prefix ARG controls sort order, see `proced-sort-interactive'."
|
|||
|
||||
(defun proced-format-time (time)
|
||||
"Format time interval TIME."
|
||||
(let* ((ftime (encode-time time 'integer))
|
||||
(let* ((ftime (time-convert time 'integer))
|
||||
(days (truncate ftime 86400))
|
||||
(ftime (mod ftime 86400))
|
||||
(hours (truncate ftime 3600))
|
||||
|
|
|
@ -3611,7 +3611,7 @@ Otherwise reindent just the current line."
|
|||
(save-excursion
|
||||
(goto-char end)
|
||||
(point-marker))
|
||||
(encode-time nil 'integer)
|
||||
(time-convert nil 'integer)
|
||||
context))
|
||||
(message "Indenting region..."))
|
||||
))
|
||||
|
@ -3619,7 +3619,7 @@ Otherwise reindent just the current line."
|
|||
(defun c-progress-update ()
|
||||
(if (not (and c-progress-info c-progress-interval))
|
||||
nil
|
||||
(let ((now (encode-time nil 'integer))
|
||||
(let ((now (time-convert nil 'integer))
|
||||
(start (aref c-progress-info 0))
|
||||
(end (aref c-progress-info 1))
|
||||
(lastsecs (aref c-progress-info 2)))
|
||||
|
|
|
@ -8600,7 +8600,7 @@ start with default arguments, then refine the slowdown regions."
|
|||
(or l (setq l 1))
|
||||
(or step (setq step 500))
|
||||
(or lim (setq lim 40))
|
||||
(let* ((timems (function (lambda () (car (encode-time nil 1000)))))
|
||||
(let* ((timems (function (lambda () (car (time-convert nil 1000)))))
|
||||
(tt (funcall timems)) (c 0) delta tot)
|
||||
(goto-char (point-min))
|
||||
(forward-line (1- l))
|
||||
|
|
|
@ -1022,7 +1022,7 @@ Do it only if `flymake-no-changes-timeout' is non-nil."
|
|||
(setq
|
||||
flymake-timer
|
||||
(run-with-idle-timer
|
||||
;; This can use encode-time instead of seconds-to-time,
|
||||
;; This can use time-convert instead of seconds-to-time,
|
||||
;; once we can assume Emacs 27 or later.
|
||||
(seconds-to-time flymake-no-changes-timeout)
|
||||
nil
|
||||
|
|
|
@ -7403,7 +7403,7 @@ only-lines."
|
|||
100
|
||||
(floor (* 100.0 (- pos (aref vhdl-progress-info 0)))
|
||||
delta))))
|
||||
(aset vhdl-progress-info 2 (encode-time nil 'integer))))
|
||||
(aset vhdl-progress-info 2 (time-convert nil 'integer))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Indentation commands
|
||||
|
@ -8149,7 +8149,7 @@ depending on parameter UPPER-CASE."
|
|||
(message "Fixing case... (%2d%s)"
|
||||
(+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
|
||||
"%")
|
||||
(setq last-update (encode-time nil 'integer))))
|
||||
(setq last-update (time-convert nil 'integer))))
|
||||
(goto-char end)))))
|
||||
|
||||
(defun vhdl-fix-case-region (beg end &optional arg)
|
||||
|
|
|
@ -1271,7 +1271,7 @@ for this to be permanent."
|
|||
|
||||
(defun tar-octal-time (timeval)
|
||||
;; Format a timestamp as 11 octal digits.
|
||||
(format "%011o" (encode-time timeval 'integer)))
|
||||
(format "%011o" (time-convert timeval 'integer)))
|
||||
|
||||
(defun tar-subfile-save-buffer ()
|
||||
"In tar subfile mode, save this buffer into its parent tar-file buffer.
|
||||
|
|
|
@ -572,7 +572,7 @@ For example, the Unix uptime command format is \"%D, %z%2h:%.2m\"."
|
|||
(interactive)
|
||||
(let ((str
|
||||
(format-seconds (or format "%Y, %D, %H, %M, %z%S")
|
||||
(encode-time
|
||||
(time-convert
|
||||
(time-since before-init-time)
|
||||
'integer))))
|
||||
(if (called-interactively-p 'interactive)
|
||||
|
|
|
@ -193,7 +193,7 @@ key cache `url-digest-auth-storage'."
|
|||
(defun url-digest-auth-make-cnonce ()
|
||||
"Compute a new unique client nonce value."
|
||||
(base64-encode-string
|
||||
(format "%016x%016x" (random) (car (encode-time nil t)))
|
||||
(format "%016x%016x" (random) (car (time-convert nil t)))
|
||||
t))
|
||||
|
||||
(defun url-digest-auth-nonce-count (_nonce)
|
||||
|
|
|
@ -181,7 +181,7 @@ Will not do anything if `url-show-status' is nil."
|
|||
(null url-show-status)
|
||||
(active-minibuffer-window)
|
||||
(= url-lazy-message-time
|
||||
(setq url-lazy-message-time (encode-time nil 'integer))))
|
||||
(setq url-lazy-message-time (time-convert nil 'integer))))
|
||||
nil
|
||||
(apply 'message args)))
|
||||
|
||||
|
|
|
@ -1183,8 +1183,8 @@ is non-nil."
|
|||
(decoded-time-second parsed-time)
|
||||
;; Compare just the seconds part of the file time,
|
||||
;; since CVS file time stamp resolution is just 1 second.
|
||||
(= (encode-time mtime 'integer)
|
||||
(encode-time parsed-time 'integer)))
|
||||
(= (time-convert mtime 'integer)
|
||||
(time-convert (encode-time parsed-time) 'integer)))
|
||||
(vc-file-setprop file 'vc-checkout-time mtime)
|
||||
(if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
|
||||
(t
|
||||
|
|
|
@ -1043,7 +1043,7 @@ hg binary."
|
|||
(let ((vc-hg-size (nth 2 dirstate-entry))
|
||||
(vc-hg-mtime (nth 3 dirstate-entry))
|
||||
(fs-size (file-attribute-size stat))
|
||||
(fs-mtime (encode-time
|
||||
(fs-mtime (time-convert
|
||||
(file-attribute-modification-time stat)
|
||||
'integer)))
|
||||
(if (and (eql vc-hg-size fs-size) (eql vc-hg-mtime fs-mtime))
|
||||
|
|
|
@ -245,8 +245,8 @@ which is the \"1006\" extension implemented in Xterm >= 277."
|
|||
;; for default value of mouse-1-click-follows-link (450msec).
|
||||
(timestamp (if (not xt-mouse-epoch)
|
||||
(progn (setq xt-mouse-epoch (float-time)) 0)
|
||||
(car (encode-time (time-since xt-mouse-epoch)
|
||||
1000))))
|
||||
(car (time-convert (time-since xt-mouse-epoch)
|
||||
1000))))
|
||||
(w (window-at x y))
|
||||
(ltrb (window-edges w))
|
||||
(left (nth 0 ltrb))
|
||||
|
|
181
src/timefns.c
181
src/timefns.c
|
@ -459,24 +459,6 @@ timespec_ticks (struct timespec t)
|
|||
/* Convert T to a Lisp integer counting HZ ticks, taking the floor.
|
||||
Assume T is valid, but check HZ. */
|
||||
static Lisp_Object
|
||||
time_hz_ticks (time_t t, Lisp_Object hz)
|
||||
{
|
||||
if (FIXNUMP (hz))
|
||||
{
|
||||
if (XFIXNUM (hz) <= 0)
|
||||
invalid_hz (hz);
|
||||
intmax_t ticks;
|
||||
if (FASTER_TIMEFNS && !INT_MULTIPLY_WRAPV (t, XFIXNUM (hz), &ticks))
|
||||
return make_int (ticks);
|
||||
}
|
||||
else if (! (BIGNUMP (hz) && 0 < mpz_sgn (XBIGNUM (hz)->value)))
|
||||
invalid_hz (hz);
|
||||
|
||||
mpz_set_time (mpz[0], t);
|
||||
mpz_mul (mpz[0], mpz[0], *bignum_integer (&mpz[1], hz));
|
||||
return make_integer_mpz ();
|
||||
}
|
||||
static Lisp_Object
|
||||
lisp_time_hz_ticks (struct lisp_time t, Lisp_Object hz)
|
||||
{
|
||||
if (FASTER_TIMEFNS && EQ (t.hz, hz))
|
||||
|
@ -538,32 +520,6 @@ timespec_to_lisp (struct timespec t)
|
|||
return Fcons (timespec_ticks (t), timespec_hz);
|
||||
}
|
||||
|
||||
/* Convert T to a Lisp timestamp. FORM specifies the timestamp format. */
|
||||
static Lisp_Object
|
||||
time_form_stamp (time_t t, Lisp_Object form)
|
||||
{
|
||||
if (NILP (form))
|
||||
form = CURRENT_TIME_LIST ? Qlist : Qt;
|
||||
if (EQ (form, Qlist))
|
||||
return list2 (hi_time (t), lo_time (t));
|
||||
if (EQ (form, Qt) || EQ (form, Qinteger))
|
||||
return INT_TO_INTEGER (t);
|
||||
return Fcons (time_hz_ticks (t, form), form);
|
||||
}
|
||||
static Lisp_Object
|
||||
lisp_time_form_stamp (struct lisp_time t, Lisp_Object form)
|
||||
{
|
||||
if (NILP (form))
|
||||
form = CURRENT_TIME_LIST ? Qlist : Qt;
|
||||
if (EQ (form, Qlist))
|
||||
return ticks_hz_list4 (t.ticks, t.hz);
|
||||
if (EQ (form, Qinteger))
|
||||
return lisp_time_seconds (t);
|
||||
if (EQ (form, Qt))
|
||||
form = t.hz;
|
||||
return Fcons (lisp_time_hz_ticks (t, form), form);
|
||||
}
|
||||
|
||||
/* From what should be a valid timestamp (TICKS . HZ), generate the
|
||||
corresponding time values.
|
||||
|
||||
|
@ -754,16 +710,14 @@ enum { DECODE_SECS_ONLY = WARN_OBSOLETE_TIMESTAMPS + 1 };
|
|||
old-format SPECIFIED_TIME. If FLAGS & WARN_OBSOLETE_TIMESTAMPS,
|
||||
diagnose what could be obsolete (HIGH . LOW) timestamps.
|
||||
|
||||
If PFORM is not null, store into *PFORM the form of SPECIFIED-TIME.
|
||||
If RESULT is not null, store into *RESULT the converted time;
|
||||
otherwise, store into *DRESULT the number of seconds since the
|
||||
start of the POSIX Epoch. Unsuccessful calls may or may not store
|
||||
results.
|
||||
|
||||
Signal an error if unsuccessful. */
|
||||
static void
|
||||
Return the form of SPECIFIED-TIME. Signal an error if unsuccessful. */
|
||||
static enum timeform
|
||||
decode_lisp_time (Lisp_Object specified_time, int flags,
|
||||
enum timeform *pform,
|
||||
struct lisp_time *result, double *dresult)
|
||||
{
|
||||
Lisp_Object high = make_fixnum (0);
|
||||
|
@ -819,12 +773,11 @@ decode_lisp_time (Lisp_Object specified_time, int flags,
|
|||
form = TIMEFORM_INVALID;
|
||||
}
|
||||
|
||||
if (pform)
|
||||
*pform = form;
|
||||
int err = decode_time_components (form, high, low, usec, psec,
|
||||
result, dresult);
|
||||
if (err)
|
||||
time_error (err);
|
||||
return form;
|
||||
}
|
||||
|
||||
/* Convert Z to time_t, returning true if it fits. */
|
||||
|
@ -928,12 +881,16 @@ list4_to_timespec (Lisp_Object high, Lisp_Object low,
|
|||
|
||||
/* Decode a Lisp list SPECIFIED_TIME that represents a time.
|
||||
If SPECIFIED_TIME is nil, use the current time.
|
||||
Signal an error if SPECIFIED_TIME does not represent a time. */
|
||||
Signal an error if SPECIFIED_TIME does not represent a time.
|
||||
If PFORM, store the time's form into *PFORM. */
|
||||
static struct lisp_time
|
||||
lisp_time_struct (Lisp_Object specified_time, enum timeform *pform)
|
||||
{
|
||||
struct lisp_time t;
|
||||
decode_lisp_time (specified_time, WARN_OBSOLETE_TIMESTAMPS, pform, &t, 0);
|
||||
enum timeform form
|
||||
= decode_lisp_time (specified_time, WARN_OBSOLETE_TIMESTAMPS, &t, 0);
|
||||
if (pform)
|
||||
*pform = form;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
@ -958,7 +915,7 @@ lisp_seconds_argument (Lisp_Object specified_time)
|
|||
{
|
||||
int flags = WARN_OBSOLETE_TIMESTAMPS | DECODE_SECS_ONLY;
|
||||
struct lisp_time lt;
|
||||
decode_lisp_time (specified_time, flags, 0, <, 0);
|
||||
decode_lisp_time (specified_time, flags, <, 0);
|
||||
struct timespec t = lisp_to_timespec (lt);
|
||||
if (! timespec_valid_p (t))
|
||||
time_overflow ();
|
||||
|
@ -1054,9 +1011,12 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
|
|||
ticks = make_integer_mpz ();
|
||||
}
|
||||
|
||||
/* Return the (TICKS . HZ) form if either argument is that way,
|
||||
/* Return an integer if the timestamp resolution is 1,
|
||||
otherwise the (TICKS . HZ) form if either argument is that way,
|
||||
otherwise the (HI LO US PS) form for backward compatibility. */
|
||||
return (aform == TIMEFORM_TICKS_HZ || bform == TIMEFORM_TICKS_HZ
|
||||
return (EQ (hz, make_fixnum (1))
|
||||
? ticks
|
||||
: aform == TIMEFORM_TICKS_HZ || bform == TIMEFORM_TICKS_HZ
|
||||
? Fcons (ticks, hz)
|
||||
: ticks_hz_list4 (ticks, hz));
|
||||
}
|
||||
|
@ -1147,7 +1107,7 @@ or (if you need time as a string) `format-time-string'. */)
|
|||
(Lisp_Object specified_time)
|
||||
{
|
||||
double t;
|
||||
decode_lisp_time (specified_time, 0, 0, 0, &t);
|
||||
decode_lisp_time (specified_time, 0, 0, &t);
|
||||
return make_float (t);
|
||||
}
|
||||
|
||||
|
@ -1436,49 +1396,27 @@ check_tm_member (Lisp_Object obj, int offset)
|
|||
}
|
||||
|
||||
DEFUN ("encode-time", Fencode_time, Sencode_time, 1, MANY, 0,
|
||||
doc: /* Convert optional TIME to a timestamp.
|
||||
Optional FORM specifies how the returned value should be encoded.
|
||||
This can act as the reverse operation of `decode-time', which see.
|
||||
doc: /* Convert TIME to a timestamp.
|
||||
|
||||
If TIME is a list (SECOND MINUTE HOUR DAY MONTH YEAR IGNORED DST ZONE)
|
||||
it is a decoded time in the style of `decode-time', so that (encode-time
|
||||
(decode-time ...)) works. TIME can also be a time value.
|
||||
See `format-time-string' for the various forms of a time value.
|
||||
For example, an omitted TIME stands for the current time.
|
||||
|
||||
If FORM is a positive integer, the time is returned as a pair of
|
||||
integers (TICKS . FORM), where TICKS is the number of clock ticks and FORM
|
||||
is the clock frequency in ticks per second. (Currently the positive
|
||||
integer should be at least 65536 if the returned value is expected to
|
||||
be given to standard functions expecting Lisp timestamps.) If FORM is
|
||||
t, the time is returned as (TICKS . PHZ), where PHZ is a platform dependent
|
||||
clock frequency in ticks per second. If FORM is `integer', the time is
|
||||
returned as an integer count of seconds. If FORM is `list', the time is
|
||||
returned as an integer list (HIGH LOW USEC PSEC), where HIGH has the
|
||||
most significant bits of the seconds, LOW has the least significant 16
|
||||
bits, and USEC and PSEC are the microsecond and picosecond counts.
|
||||
Returned values are rounded toward minus infinity. Although an
|
||||
omitted or nil FORM currently acts like `list', this is planned to
|
||||
change, so callers requiring list timestamps should specify `list'.
|
||||
TIME is a list (SECOND MINUTE HOUR DAY MONTH YEAR IGNORED DST ZONE).
|
||||
in the style of `decode-time', so that (encode-time (decode-time ...)) works.
|
||||
In this list, ZONE can be nil for Emacs local time, t for Universal
|
||||
Time, `wall' for system wall clock time, or a string as in the TZ
|
||||
environment variable. It can also be a list (as from
|
||||
`current-time-zone') or an integer (as from `decode-time') applied
|
||||
without consideration for daylight saving time. If ZONE specifies a
|
||||
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.
|
||||
|
||||
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,
|
||||
where DST assumed to be -1 and FORM is omitted. If there are more
|
||||
than 6 arguments the *last* argument is used as ZONE and any other
|
||||
extra arguments are ignored, so that (apply #\\='encode-time
|
||||
extra arguments are ignored, so that (apply #'encode-time
|
||||
(decode-time ...)) works; otherwise ZONE is assumed to be nil.
|
||||
|
||||
If the input is a decoded time, ZONE is nil for Emacs local time, t
|
||||
for Universal Time, `wall' for system wall clock time, or a string as
|
||||
in the TZ environment variable. It can also be a list (as from
|
||||
`current-time-zone') or an integer (as from `decode-time') applied
|
||||
without consideration for daylight saving time.
|
||||
|
||||
If the input is a decoded time and ZONE specifies a time zone with
|
||||
daylight-saving transitions, DST is t for daylight saving time and nil
|
||||
for standard time. If DST is -1, the daylight saving flag is guessed.
|
||||
|
||||
Out-of-range values for SECOND, MINUTE, HOUR, DAY, or MONTH are allowed;
|
||||
for example, a DAY of 0 means the day preceding the given month.
|
||||
Year numbers less than 100 are treated just like other year numbers.
|
||||
|
@ -1487,26 +1425,19 @@ If you want them to stand for years in this century, you must do that yourself.
|
|||
Years before 1970 are not guaranteed to work. On some systems,
|
||||
year values as low as 1901 do work.
|
||||
|
||||
usage: (encode-time &optional TIME FORM &rest OBSOLESCENT-ARGUMENTS) */)
|
||||
usage: (encode-time TIME &rest OBSOLESCENT-ARGUMENTS) */)
|
||||
(ptrdiff_t nargs, Lisp_Object *args)
|
||||
{
|
||||
struct tm tm;
|
||||
Lisp_Object form = Qnil, zone = Qnil;
|
||||
Lisp_Object zone = Qnil;
|
||||
Lisp_Object a = args[0];
|
||||
tm.tm_isdst = -1;
|
||||
|
||||
if (nargs <= 2)
|
||||
if (nargs == 1)
|
||||
{
|
||||
if (nargs == 2)
|
||||
form = args[1];
|
||||
Lisp_Object tail = a;
|
||||
for (int i = 0; i < 9; i++, tail = XCDR (tail))
|
||||
if (! CONSP (tail))
|
||||
{
|
||||
struct lisp_time t;
|
||||
decode_lisp_time (a, 0, 0, &t, 0);
|
||||
return lisp_time_form_stamp (t, form);
|
||||
}
|
||||
CHECK_CONS (tail);
|
||||
tm.tm_sec = check_tm_member (XCAR (a), 0); a = XCDR (a);
|
||||
tm.tm_min = check_tm_member (XCAR (a), 0); a = XCDR (a);
|
||||
tm.tm_hour = check_tm_member (XCAR (a), 0); a = XCDR (a);
|
||||
|
@ -1543,7 +1474,43 @@ usage: (encode-time &optional TIME FORM &rest OBSOLESCENT-ARGUMENTS) */)
|
|||
if (tm.tm_wday < 0)
|
||||
time_error (mktime_errno);
|
||||
|
||||
return time_form_stamp (value, form);
|
||||
return (CURRENT_TIME_LIST
|
||||
? list2 (hi_time (value), lo_time (value))
|
||||
: INT_TO_INTEGER (value));
|
||||
}
|
||||
|
||||
DEFUN ("time-convert", Ftime_convert, Stime_convert, 1, 2, 0,
|
||||
doc: /* Convert TIME value to a Lisp timestamp.
|
||||
With optional FORM, convert to that timestamp form.
|
||||
Truncate the returned value toward minus infinity.
|
||||
|
||||
If FORM is nil (the default), return the the same form as `current-time'.
|
||||
If FORM is a positive integer, return a pair of integers (TICKS . FORM),
|
||||
where TICKS is the number of clock ticks and FORM is the clock frequency
|
||||
in ticks per second. (Currently the positive integer should be at least
|
||||
65536 if the returned value is expected to be given to standard functions
|
||||
expecting Lisp timestamps.) If FORM is t, return (TICKS . PHZ), where
|
||||
PHZ is a suitable clock frequency in ticks per second. If FORM is
|
||||
`integer', return an integer count of seconds. If FORM is `list',
|
||||
return an integer list (HIGH LOW USEC PSEC), where HIGH has the most
|
||||
significant bits of the seconds, LOW has the least significant 16
|
||||
bits, and USEC and PSEC are the microsecond and picosecond counts. */)
|
||||
(Lisp_Object time, Lisp_Object form)
|
||||
{
|
||||
struct lisp_time t;
|
||||
enum timeform input_form = decode_lisp_time (time, 0, &t, 0);
|
||||
if (NILP (form))
|
||||
form = CURRENT_TIME_LIST ? Qlist : Qt;
|
||||
if (EQ (form, Qlist))
|
||||
return ticks_hz_list4 (t.ticks, t.hz);
|
||||
if (EQ (form, Qinteger))
|
||||
return FASTER_TIMEFNS && INTEGERP (time) ? time : lisp_time_seconds (t);
|
||||
if (EQ (form, Qt))
|
||||
form = t.hz;
|
||||
if (FASTER_TIMEFNS
|
||||
&& input_form == TIMEFORM_TICKS_HZ && EQ (form, XCDR (time)))
|
||||
return time;
|
||||
return Fcons (lisp_time_hz_ticks (t, form), form);
|
||||
}
|
||||
|
||||
DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0,
|
||||
|
@ -1551,9 +1518,12 @@ DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0,
|
|||
The time is returned as a list of integers (HIGH LOW USEC PSEC).
|
||||
HIGH has the most significant bits of the seconds, while LOW has the
|
||||
least significant 16 bits. USEC and PSEC are the microsecond and
|
||||
picosecond counts. Use `encode-time' if you need a particular
|
||||
timestamp form; for example, (encode-time nil \\='integer) returns the
|
||||
current time in seconds. */)
|
||||
picosecond counts.
|
||||
|
||||
In a future Emacs version, the format of the returned timestamp is
|
||||
planned to change. Use `time-convert' if you need a particular
|
||||
timestamp form; for example, (time-convert nil \\='integer) returns
|
||||
the current time in seconds. */)
|
||||
(void)
|
||||
{
|
||||
return make_lisp_time (current_timespec ());
|
||||
|
@ -1798,6 +1768,7 @@ syms_of_timefns (void)
|
|||
DEFSYM (Qencode_time, "encode-time");
|
||||
|
||||
defsubr (&Scurrent_time);
|
||||
defsubr (&Stime_convert);
|
||||
defsubr (&Stime_add);
|
||||
defsubr (&Stime_subtract);
|
||||
defsubr (&Stime_less_p);
|
||||
|
|
|
@ -49,14 +49,14 @@
|
|||
(let* ((tc (current-time))
|
||||
(delta-ticks 1000)
|
||||
(hz 128000)
|
||||
(tce (encode-time tc hz))
|
||||
(tce (time-convert tc hz))
|
||||
(tc+delta (time-add tce (cons delta-ticks hz)))
|
||||
(tc+deltae (encode-time tc+delta hz))
|
||||
(tc+deltae (time-convert tc+delta hz))
|
||||
(tc+delta-ticks (car tc+deltae))
|
||||
(tc-nexte (cons (- tc+delta-ticks (% tc+delta-ticks delta-ticks)) hz))
|
||||
(nt (timer-next-integral-multiple-of-time
|
||||
tc (/ (float delta-ticks) hz)))
|
||||
(nte (encode-time nt hz)))
|
||||
(nte (time-convert nt hz)))
|
||||
(should (equal tc-nexte nte))))
|
||||
|
||||
(ert-deftest timer-next-integral-multiple-of-time-3 ()
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
(cons 1000000000000 (1+ most-positive-fixnum)))))
|
||||
(dolist (a time-values)
|
||||
(let* ((d (ignore-errors (decode-time a t)))
|
||||
(e (encode-time d))
|
||||
(e (if d (encode-time d)))
|
||||
(diff (float-time (time-subtract a e))))
|
||||
(should (or (not d)
|
||||
(and (<= 0 diff) (< diff 1))))))))
|
||||
|
|
Loading…
Reference in a new issue