For a while now I've been using the following function:

(defun current-time-as-float ()
  (let ((tm (current-time)))
    (+
     (* 65536.0 (nth 0 tm))
     (nth 1 tm)
     (/ (nth 2 tm) 1000000.0))))

(current-time-as-float)
  --> 1129642168.966545

It returns the current time as a single floating-point number.  I find
it very convenient because its return value can be manipulated with
normal arithmetic functions, such as subtraction.  This is useful for
measuring of passage of time, as well as for recording time stamps.
The truncated value can also be passed to external code that expects
the Unix-style number of seconds since Epoch.

While the above function wasn't hard to write for me, it probably
would be for a beginner.  I'm not proposing that you include the above
function as-is, but such functionality in some form, either as
an optional argument to current-time, or as a separate (more
aptly-named) function would be useful.

Later, functions like format-time-string could start accepting such
floating-point arguments as well.


_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

Reply via email to