[Top][All Lists]

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

Re: encode-time vs decode-time

From: Lars Ingebrigtsen
Subject: Re: encode-time vs decode-time
Date: Wed, 31 Jul 2019 21:03:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Paul Eggert <address@hidden> writes:

>> this is very confusing indeed
> To some extent the confusion is inherent: there are a lot of useful
> ways to represent and manipulate times, and people unfamiliar with the
> issues will find this complexity confusing. That being said, it would
> be good to simplify the Emacs API for time without significantly
> hurting functionality or compatibility.
> So, how about this idea. First we go along the lines of your
> suggestion, and change decode-time to return a ninth slot with a
> numerator-denominator pair that preserves all the precision of its
> argument. Second, we change (encode-time TIME t) so that it also
> preserves all the precision of its argument. This will cause
> (encode-time (decode-time TIME) t) to return a value equivalent to
> TIME, which will simplify roundtripping.

I think this sounds workable, but I think it would be even better to
introduce some new functions instead of overloading our poor encode-time

When you did the major sanitation in this area last year (which was
overall a very good thing), you did stuff like 

-       (now (string-to-number (format-time-string "%s")))
+       (now (encode-time nil 'integer))


-       (now (float-time))
+       (now (encode-time nil 'integer))

and many similar transforms.  The new code is definitely better than the
old code, and it's not more cryptic than it used to be, really.

However, I think it would have been even better to introduce a new
function to enable people who are unfamiliar with how this all works to
just read the code and understand what it's doing.

So I think the things up above there should really be calls to a new
function `get-current-time', that returns the same thing as
`(encode-time nil 'integer)'.  It should default to `integer', but can
have an optional argument that says what form of "internal second time
format" to return (i.e., `list', `t').

And then, finally, I think there should be a function to convert between
these "internal second time" formats.  Like...  `convert-time-format',
which would be like `(encode-time time 'list)' (etc).

And then leave encode-time/decode-time a simple pair that would do
nothing but convert between "internal second time format" and "decoded
time format".

(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

reply via email to

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