emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: encode-time vs decode-time


From: Paul Eggert
Subject: Re: encode-time vs decode-time
Date: Wed, 21 Aug 2019 13:20:50 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

Adam Porter wrote:
Forgive me for being late to this discussion.  After struggling with
using and manipulating date/time values in Emacs, I came up with this:

https://github.com/alphapapa/ts.el

I looked briefly at it, and don't see any compatibility issues - not that I understand all the code, which depends on packages I don't use.

The code's comments say that format-time-string is too slow. What performance issues did you run into? At any rate I think you'll find that this:

  (string-to-number (format-time-string "%Y" (ts-unix struct)))

is more efficient written this way:

  (nth 5 (decode-time (ts-unix struct)))

and I expect you can speed up the code further by caching the entire result of decode-time instead of calling format-time-string for each component.

Also, the timestamp functions in Emacs 27 should simplify ts.el, once you can assume Emacs 27. For example, in Emacs 27 you can do something like this:

  (decoded-time-add X (make-decoded-time :year 10))

to add 10 years to a broken-down timestamp X.

One more thing: ts.el's extensive use of float-time is fine for calendrical applications but has limited resolution (2**-22 s or about 2e-7 s for today's timestamps) and so would be problematic for apps requiring higher-resolution timestamps.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]