unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Andy Moreton <andrewjmoreton@gmail.com>, emacs-devel@gnu.org
Subject: Re: encode-time vs decode-time
Date: Wed, 31 Jul 2019 21:03:07 +0200	[thread overview]
Message-ID: <87v9viuivo.fsf@mouse.gnus.org> (raw)
In-Reply-To: <502b23f8-58ed-38ff-ae50-fae391129a10@cs.ucla.edu> (Paul Eggert's message of "Tue, 30 Jul 2019 12:54:21 -0500")

Paul Eggert <eggert@cs.ucla.edu> 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
function.

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))

and

-	(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



  parent reply	other threads:[~2019-07-31 19:03 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-29  9:48 Support for sub-second time in decoded time Lars Ingebrigtsen
2019-07-29 14:03 ` Stefan Monnier
2019-07-29 14:12   ` Lars Ingebrigtsen
2019-07-29 14:43     ` Stefan Monnier
2019-07-29 15:00       ` Lars Ingebrigtsen
2019-07-29 17:50         ` Stefan Monnier
2019-07-30 11:33           ` Lars Ingebrigtsen
2019-07-29 16:08     ` encode-time vs decode-time Stefan Monnier
2019-07-30 10:32       ` Lars Ingebrigtsen
2019-07-30 11:34         ` Andy Moreton
2019-07-30 11:37           ` Lars Ingebrigtsen
2019-07-30 17:54             ` Paul Eggert
2019-07-30 22:50               ` Paul Eggert
2019-07-31 19:03               ` Lars Ingebrigtsen [this message]
2019-07-31 19:31                 ` Stefan Monnier
2019-08-06  1:48                 ` Paul Eggert
2019-08-06 14:21                   ` Eli Zaretskii
2019-08-06 15:59                     ` Paul Eggert
2019-08-06 18:23                       ` Eli Zaretskii
2019-08-07  1:02                         ` Paul Eggert
2019-08-07  2:41                           ` Stefan Monnier
2019-08-07 14:47                             ` Eli Zaretskii
2019-08-11 23:39                               ` Lars Ingebrigtsen
2019-08-17  6:47                             ` Paul Eggert
2019-08-07 11:33                           ` Lars Ingebrigtsen
2019-08-17  7:54                             ` Paul Eggert
2019-08-17  8:16                               ` Eli Zaretskii
2019-08-17  9:33                                 ` Paul Eggert
2019-08-17 20:46                               ` Lars Ingebrigtsen
2019-08-17 20:56                                 ` Paul Eggert
2019-08-17 21:42                                   ` Stefan Monnier
2019-08-17 22:53                                     ` Paul Eggert
2019-08-19 21:12                                       ` Stefan Monnier
2019-08-21 10:55                                         ` Adam Porter
2019-08-21 20:20                                           ` Paul Eggert
2019-08-26 10:59                                             ` Adam Porter
2019-08-26 21:35                                               ` Paul Eggert
2019-08-07 14:44                           ` Eli Zaretskii
2019-08-07 11:41                   ` Lars Ingebrigtsen
2019-08-17  9:25                     ` Paul Eggert
2019-08-17 20:51                       ` Lars Ingebrigtsen
2019-07-29 14:23 ` Support for sub-second time in decoded time Eli Zaretskii
2019-07-29 14:59   ` Lars Ingebrigtsen
2019-07-29 16:46 ` Paul Eggert
2019-07-30 11:43   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v9viuivo.fsf@mouse.gnus.org \
    --to=larsi@gnus.org \
    --cc=andrewjmoreton@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).