]> git.eshelyaron.com Git - emacs.git/commitdiff
New function time-convert
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 6 Aug 2019 00:38:52 +0000 (17:38 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 6 Aug 2019 01:37:29 +0000 (18:37 -0700)
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).

42 files changed:
doc/lispref/elisp.texi
doc/lispref/os.texi
doc/misc/emacs-mime.texi
etc/NEWS
lisp/calendar/cal-dst.el
lisp/calendar/icalendar.el
lisp/calendar/time-date.el
lisp/calendar/timeclock.el
lisp/cedet/ede/detect.el
lisp/completion.el
lisp/ecomplete.el
lisp/emacs-lisp/byte-opt.el
lisp/emacs-lisp/cl-extra.el
lisp/emacs-lisp/elint.el
lisp/emacs-lisp/timer.el
lisp/find-lisp.el
lisp/gnus/gnus-diary.el
lisp/gnus/gnus-group.el
lisp/gnus/gnus-icalendar.el
lisp/gnus/nnrss.el
lisp/gnus/nnspool.el
lisp/net/ntlm.el
lisp/net/pop3.el
lisp/obsolete/vc-arch.el
lisp/org/org-clock.el
lisp/org/org-id.el
lisp/org/ox-publish.el
lisp/proced.el
lisp/progmodes/cc-cmds.el
lisp/progmodes/cperl-mode.el
lisp/progmodes/flymake.el
lisp/progmodes/vhdl-mode.el
lisp/tar-mode.el
lisp/time.el
lisp/url/url-auth.el
lisp/url/url-util.el
lisp/vc/vc-cvs.el
lisp/vc/vc-hg.el
lisp/xt-mouse.el
src/timefns.c
test/lisp/emacs-lisp/timer-tests.el
test/src/timefns-tests.el

index 1f844478f74be591c2eda09bcff0f1ef2a0ba51c..1ff62118cdd001ebddc3f50160a772713f530722 100644 (file)
@@ -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
index 7bb9833467de90da25ab01a9edfed41d92d67a2a..b26d903707b865101c40bddcb71806c5df5434d4 100644 (file)
@@ -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}
index 1f384f4f2700a16d5f95ba2dd4493215bcab34d4..eb829b06124321048d811da46fff8284684e6d24 100644 (file)
@@ -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.
index 7b8916edd69bcc0a48bd6316eadb323633f2c27d..116bdb961c36d68606e81aaa9595cd27340e144b 100644 (file)
--- a/etc/NEWS
+++ b/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
index 510cd6808e4384f2be80b84e68f476dbe79ce408..2d3b1f8c81865bdcbe42a807aa1e2f5de349b474 100644 (file)
@@ -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
index cf3315b45db4fe82806c39c9d8915f0aa64adbb1..c2688705e3037c18a82017439d4661631b540fad 100644 (file)
@@ -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....
index c0565b3cfb72c85703f74d38744b8b42810575bd..7505332011b770ee9e5b26f939d56e6e84f4e323 100644 (file)
@@ -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))
index 60586e7aceda8f29559a226b12022a81bfc6fcc3..ee7cf17b04285a8834fbe88fb4d9cf342c61bb93 100644 (file)
@@ -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)
index d65abce4b3cf137fdc48390cc317992e5a02fa38..f65481b0c8dbaab88929f8607b84ef93bfaf4339 100644 (file)
@@ -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.") )))
index b9c3a21f5eaae08b9c5fa8553ed5dce03f9e848a..77761d695bf58604d9a2a3ec9d6f53e98f924f38 100644 (file)
@@ -432,7 +432,7 @@ Used to decide whether to save completions.")
 
 \f
 (defun cmpl-hours-since-origin ()
-  (floor (encode-time nil 'integer) 3600))
+  (floor (time-convert nil 'integer) 3600))
 \f
 ;;---------------------------------------------------------------------------
 ;; "Symbol" parsing functions
index d9f34ef0c00357206b30d07d0c7e7950af9a080f..1cacd4735087d31fdd89b9958904926c3f71dcc4 100644 (file)
@@ -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))
index ecaa845fd3e123530f09c4032dc6250b8f7d850d..22fea1b8da9d41d05ad599b457267779dc882e61 100644 (file)
         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
index ca33c56a9580f1d9ad8ba65a5fda4a6d688d5e3e..4dc2e9de58f6b57ad522ee89cfb1decd64a26da4 100644 (file)
@@ -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
index 6927921bdac0ed1b0068d2f7cf2a875b96aac0e6..b7ef6eeb2ae8acfcb804cd51e38a6f9a0608430e 100644 (file)
@@ -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)
index 400f00a85b5a4ed5e1aee90febdd912529a0100d..561cc70078f5b41ef607c8c988127129041e49c0 100644 (file)
@@ -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
index 073e2bc573f5859395dbd6eee82ede2ac7bfc29c..5a10ec3b47c0763c4071c93a9a08733f1d59be51 100644 (file)
@@ -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
index 0e78f2b899265c0330b7196bcea9ac6a3a04925b..16973074be420ab14c3f7f1b0638f16112901362 100644 (file)
@@ -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)))
index 7e0ceec17b627424d92c1f633eaa576834b560ef..b40379c4f5ca3da29f4bad20e23bb3bbea5169ba 100644 (file)
@@ -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)
index 529cafe23e87293d2661ff0ed067574a518a3b27..7d11b5699bb90f2ab8253fc9cfab72a9af408072 100644 (file)
@@ -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)
index 958745d57902544279cd27e3dbfcd1268ac2bc65..955432764e6ee34e2dc8327b1e912030cfd5848a 100644 (file)
@@ -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)
index 767631c68593b8ea9ce42e55e061ee1a91ad3546..31ed3e97ef993129950727b72a239a057720a880 100644 (file)
@@ -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]+ ")
index 88c561910cb6b38a8c0ed5e87c82fd8d7ed4c116..aae770062025672c26acd096e1e32280ab9e2304 100644 (file)
@@ -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)
index 4bf50c0d22640af2e0a5543a7fb73b9f72952f3b..5f1cd94eb605397cb09349d28e6f25c2e03ad07b 100644 (file)
@@ -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))
index 925289102c154873b52ac91c9f7a2fdf4d0fff24..1d41052037bf1cb340f166e0fa74f4a1a54a46a4 100644 (file)
@@ -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))))
index 62c7cd92d12aa7ec27ec156e35f16befad51db4b..4667890b421e152c39e8510d2410d25a26513e3e 100644 (file)
@@ -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)))
index fe439a7b89da640772752abf22fc9a7be0819957..34084bfa1097da6fe8c98ff9eed9eefb4cf34ff4 100644 (file)
@@ -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)))
index 9126647e7c3e764b75093d18263d83d6d4d4c0ed..237b2ff8163f878ac70b51321ca5520f29ac2eee 100644 (file)
@@ -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)
index 5f35fa34a070e7c8b566bf0e05941c40c8058fcd..db8bdb5ac80a7a0801c02d6f8fd1950e48203417 100644 (file)
@@ -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))
index 2ccdc1d0bc8c5a23af649b609454bab743b8a825..acf4c4ad158fb1d2121e530f67ef8e0aea907885 100644 (file)
@@ -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)))
index d5c404c7d2f0e57d87a66d3fdb7782d4c280ac7c..8e94da082a385d8e751d27a8e69ffb6d530919d5 100644 (file)
@@ -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))
index e8a4334fe9673480dfca56284967d0dcac9e7ae3..6d47c8bb170de21f654505e769ab031f0fc5671a 100644 (file)
@@ -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
index 9eedbf9cbc9a84115a9dbeda7db3e5448c38fc40..2c947f3b05011f4dd937917b81af4b9e054eeb16 100644 (file)
@@ -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)
index cf777817666176ec771b9a3ff92ce930f8a5ceb8..713f3d944bcca4f1996d17ea6028954840ca0fb3 100644 (file)
@@ -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.
index 35157c5e807919e0c452386774de43b5b8711e11..95e095af5dde5f29b678142cdddc2ad7e2fcc4f9 100644 (file)
@@ -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)
index b78544e3f37cfb9d336889c95d76f8848b0da59c..b9643c279ff62e66b93c8fabe7922dbfc3c2c29b 100644 (file)
@@ -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)
index a46e7bb3855ee6a3aafdc797572d06c1298b036a..0b3c2839266c987cd5ddc2fd0850f3656f968e94 100644 (file)
@@ -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)))
 
index b33a106f3a94a08f26b3103d2c8172bde365d520..d84700fc17644de7b83832525c7a359b67747c7c 100644 (file)
@@ -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
index 876d824ceacd63f60d98f374b4cfbaf2a03a1aac..f287adf24237dc18381e61aa7779be9edcbbe679 100644 (file)
@@ -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))
index 5ff718292d3557c304560667de489b468c8cf4b9..b53174b7bd5bdbc180c2b09fb4683294cd41555c 100644 (file)
@@ -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))
index ee43014979ec82f75e9f1d41ca59d108769fdfc6..4310409ab7cf85e1d1c41411e61355cde17700b9 100644 (file)
@@ -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, &lt, 0);
+  decode_lisp_time (specified_time, flags, &lt, 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);
index bd2dcbe554e71dae86539fb6c96e339872e90474..676730ead2d2117263bdac605a423b1f28fc5ed6 100644 (file)
   (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 ()
index 2c90af757f01ecb85b86ebc6c5bb3eda46c38bfe..fae058edf9398f19b2285b8fdc5bee72d7b5102c 100644 (file)
@@ -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))))))))