From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hrvoje Niksic Newsgroups: gmane.emacs.devel Subject: Current time as floating point number Date: 18 Oct 2005 15:45:20 +0200 Message-ID: <874q7f7xcf.fsf@xemacs.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1129643289 16575 80.91.229.2 (18 Oct 2005 13:48:09 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 18 Oct 2005 13:48:09 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 18 15:48:06 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1ERrmt-0002r4-Px for ged-emacs-devel@m.gmane.org; Tue, 18 Oct 2005 15:45:56 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ERrmt-0001BZ-C6 for ged-emacs-devel@m.gmane.org; Tue, 18 Oct 2005 09:45:55 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ERrmQ-00013j-PX for emacs-devel@gnu.org; Tue, 18 Oct 2005 09:45:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ERrmO-00012v-RZ for emacs-devel@gnu.org; Tue, 18 Oct 2005 09:45:26 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ERrmO-00012n-JP for emacs-devel@gnu.org; Tue, 18 Oct 2005 09:45:24 -0400 Original-Received: from [195.29.150.97] (helo=ls405.htnet.hr) by monty-python.gnu.org with esmtp (Exim 4.34) id 1ERrmO-0005id-F7 for emacs-devel@gnu.org; Tue, 18 Oct 2005 09:45:24 -0400 Original-Received: from ls401.t-com.hr (ls401.t-com.hr [195.29.150.236]) by ls405.htnet.hr (0.0.0/8.12.10) with ESMTP id j9IDjLWl019774 for ; Tue, 18 Oct 2005 15:45:22 +0200 Original-Received: from ls401.t-com.hr (localhost.localdomain [127.0.0.1]) by ls401.t-com.hr (Qmlai) with ESMTP id B209970003 for ; Tue, 18 Oct 2005 15:45:22 +0200 (CEST) X-Envelope-Sender: hniksic@xemacs.org Original-Received: from localhost.localdomain (83-131-16-128.adsl.net.t-com.hr [83.131.16.128]) by ls401.t-com.hr (Qmlai) with ESMTP id 417BEA8039 for ; Tue, 18 Oct 2005 15:45:22 +0200 (CEST) Original-Received: by localhost.localdomain (Postfix, from userid 1000) id 9DE5F434003; Tue, 18 Oct 2005 15:45:21 +0200 (CEST) Original-To: emacs-devel@gnu.org Original-Lines: 27 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:44261 Archived-At: 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.