all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* What do I use if not `float-time'?
@ 2010-01-06 15:15 Deniz Dogan
  2010-01-06 15:29 ` Davis Herring
  0 siblings, 1 reply; 5+ messages in thread
From: Deniz Dogan @ 2010-01-06 15:15 UTC (permalink / raw)
  To: Emacs-Devel devel

In the documentation for `float-time' in "(elisp) Time of Day" I read
the following: "_Warning_: Since the result is floating point, it may
not be exact.  Do not use this function if precise time stamps are
required."

Okay, so what do I use instead? I just want a "UNIX timestamp" as an
integer or string. What's the idiomatic way to get that?

-- 
Deniz Dogan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What do I use if not `float-time'?
  2010-01-06 15:15 What do I use if not `float-time'? Deniz Dogan
@ 2010-01-06 15:29 ` Davis Herring
  2010-01-06 20:27   ` Juri Linkov
  2010-01-06 20:40   ` Deniz Dogan
  0 siblings, 2 replies; 5+ messages in thread
From: Davis Herring @ 2010-01-06 15:29 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: Emacs-Devel devel

> Okay, so what do I use instead? I just want a "UNIX timestamp" as an
> integer or string. What's the idiomatic way to get that?

Use `current-time'.  The trick is that you then have to deal with multiple
integers (because Emacs ints are (often) shorter than 32 bits). 
`float-time' exists to avoid that inconvenience at the cost of another. 
In practice, using the integer parts of calls to (float-time) should be
fine so long as you don't do too much arithmetic on them: doubles have 53
bits of mantissa, and so can represent any reasonable traditional
(integer) time stamp exactly.

To get a string version of the integer part (which you can't safely turn
into an integer!), you can just use (format-time-string "%s").

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What do I use if not `float-time'?
  2010-01-06 15:29 ` Davis Herring
@ 2010-01-06 20:27   ` Juri Linkov
  2010-01-07  1:08     ` Stephen J. Turnbull
  2010-01-06 20:40   ` Deniz Dogan
  1 sibling, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2010-01-06 20:27 UTC (permalink / raw)
  To: herring; +Cc: emacs-devel, Deniz Dogan

>> Okay, so what do I use instead? I just want a "UNIX timestamp" as an
>> integer or string. What's the idiomatic way to get that?
>
> Use `current-time'.  The trick is that you then have to deal with multiple
> integers (because Emacs ints are (often) shorter than 32 bits).

Is a list of integers still necessary for 64-bit machines where
most-positive-fixnum is greater than the number of microseconds
since January 1, 1970.

-- 
Juri Linkov
http://www.jurta.org/emacs/




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What do I use if not `float-time'?
  2010-01-06 15:29 ` Davis Herring
  2010-01-06 20:27   ` Juri Linkov
@ 2010-01-06 20:40   ` Deniz Dogan
  1 sibling, 0 replies; 5+ messages in thread
From: Deniz Dogan @ 2010-01-06 20:40 UTC (permalink / raw)
  To: herring; +Cc: Emacs-Devel devel

2010/1/6 Davis Herring <herring@lanl.gov>:
>> Okay, so what do I use instead? I just want a "UNIX timestamp" as an
>> integer or string. What's the idiomatic way to get that?
>
> Use `current-time'.  The trick is that you then have to deal with multiple
> integers (because Emacs ints are (often) shorter than 32 bits).
> `float-time' exists to avoid that inconvenience at the cost of another.
> In practice, using the integer parts of calls to (float-time) should be
> fine so long as you don't do too much arithmetic on them: doubles have 53
> bits of mantissa, and so can represent any reasonable traditional
> (integer) time stamp exactly.
>
> To get a string version of the integer part (which you can't safely turn
> into an integer!), you can just use (format-time-string "%s").
>

Thanks, the `format-time-string' trick works like a charm. I actually
needed a string in the first place, so that was perfect.

-- 
Deniz Dogan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What do I use if not `float-time'?
  2010-01-06 20:27   ` Juri Linkov
@ 2010-01-07  1:08     ` Stephen J. Turnbull
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen J. Turnbull @ 2010-01-07  1:08 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Deniz Dogan, emacs-devel

Juri Linkov writes:
 > >> Okay, so what do I use instead? I just want a "UNIX timestamp" as an
 > >> integer or string. What's the idiomatic way to get that?
 > >
 > > Use `current-time'.  The trick is that you then have to deal with multiple
 > > integers (because Emacs ints are (often) shorter than 32 bits).
 > 
 > Is a list of integers still necessary for 64-bit machines where
 > most-positive-fixnum is greater than the number of microseconds
 > since January 1, 1970.

Yes, because the API is defined that way.  You could rewrite callers
to check whether it's just an integer or a list, but why bother?  This
is not called that often.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-01-07  1:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-06 15:15 What do I use if not `float-time'? Deniz Dogan
2010-01-06 15:29 ` Davis Herring
2010-01-06 20:27   ` Juri Linkov
2010-01-07  1:08     ` Stephen J. Turnbull
2010-01-06 20:40   ` Deniz Dogan

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.