all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 27.0.60; Asymmetry between (days-to-time) and (time-to-days)
@ 2020-03-24  9:18 Kevin Liu
  2020-03-24 16:51 ` Paul Eggert
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Liu @ 2020-03-24  9:18 UTC (permalink / raw)
  To: emacs-devel

The asymmetry between (days-to-time) and (time-to-days) is quite surprising:

(format-time-string "%Y" (days-to-time (time-to-days (current-time))))
"3989"

One could work around this by using (time-to-number-of-days) which uses
the epoch time like (days-to-time), but that itself is awkwardly
asymmetric as it returns a float, as well as the asymmetric naming.

It's probably unrealistic that any existing behavior be changed, but it
would at least be nice to have a builtin function that is the inverse of
(time-to-days).  Org-mode, for example, seems to use the Gregorian
convention of (time-to-days) throughout, and to convert a (org-today) to
a time requires this mess:

(format-time-string "%Y" (days-to-time (- (org-today) 719162)))
"2020"



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

* Re: 27.0.60; Asymmetry between (days-to-time) and (time-to-days)
  2020-03-24  9:18 27.0.60; Asymmetry between (days-to-time) and (time-to-days) Kevin Liu
@ 2020-03-24 16:51 ` Paul Eggert
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Eggert @ 2020-03-24 16:51 UTC (permalink / raw)
  To: Kevin Liu; +Cc: emacs-devel

On 3/24/20 2:18 AM, Kevin Liu wrote:
> The asymmetry between (days-to-time) and (time-to-days) is quite surprising:
> 
> (format-time-string "%Y" (days-to-time (time-to-days (current-time))))
> "3989"

Even if time-to-days and days-to-time were inverses, this usage would be dubious 
since the conversion back and forth would discard the fractional date and that 
could cause format-time-string to do the wrong thing when the timestamp was near 
a year boundary in a non-UTC timezone.

> It's probably unrealistic that any existing behavior be changed, but it
> would at least be nice to have a builtin function that is the inverse of
> (time-to-days).

We could add an optional argument to days-to-time; if it's t then days-to-time 
could add 719162 to its argument before converting (or whatever the magic number 
happens to be; I didn't check this).



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

end of thread, other threads:[~2020-03-24 16:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-24  9:18 27.0.60; Asymmetry between (days-to-time) and (time-to-days) Kevin Liu
2020-03-24 16:51 ` Paul Eggert

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.