emacs-devel
[Top][All Lists]
Advanced

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

Re: Support for sub-second time in decoded time


From: Lars Ingebrigtsen
Subject: Re: Support for sub-second time in decoded time
Date: Mon, 29 Jul 2019 16:12:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> `current-time' returns its data as (HIGH LOW USEC PSEC), but now that we
>> have bignum support, perhaps we don't need to do it this way.  What
>> about just having a field in decoded times that's the fraction of a
>> second?  So 34.5603 seconds would be represented as
>>
>> (34 ... 5603)
>
> `encode-time` uses a fraction-representation (NOM . DENOM), which is
> probably easier to manipulate.

You mean internally?  It doesn't seem to be mentioned in the doc string,
but it's an entire essay now...

> [ Note: I find `encode-time` vs `decode-time` very confusing.  ]

I think the pair makes sense on the same level as
{decode,encode}-coding-string does.  That is, encoded time is what Emacs
uses internally for most things, and decoded time is pretty close to
what you er find in nature.

Or at least it used to be; `endode-time' has gotten really complicated
lately, and the doc string doesn't seem to be correct, ether, for some
of the more odd things it apparently does.

(let ((time (current-time)))
  (equal time (encode-time time)))
=> t

(encode-time)
-> Debugger entered--Lisp error: (wrong-number-of-arguments encode-time 0)

But if we ignore all that, it's still conceptually sound.  :-)

---
encode-time is a built-in function in ‘src/timefns.c’.

(encode-time &optional TIME FORM &rest OBSOLESCENT-ARGUMENTS)

  Probably introduced at or before Emacs version 19.29.
  This function does not change global state, including the match data.

Convert optional TIME to a timestamp.
Optional FORM specifies how the returned value should be encoded.
This can act as the reverse operation of ‘decode-time’, which see.

If TIME is a list (SECOND MINUTE HOUR DAY MONTH YEAR IGNORED DST ZONE)
it is a decoded time in the style of ‘decode-time’, so that (encode-time
(decode-time ...)) works.  TIME can also be a time value.
See ‘format-time-string’ for the various forms of a time value.
For example, an omitted TIME stands for the current time.
---

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