unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#66502: 30.0.50; [PATCH; DOC] time-to-days and days-to-time use different epochs
@ 2023-10-12 17:23 Bob Rogers
  2023-10-14  9:02 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Bob Rogers @ 2023-10-12 17:23 UTC (permalink / raw)
  To: 66502

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 476 bytes --]

   Imagine my surprise when converting back using days-to-time gave me
something almost two millenia in the future.  Of course, the problem was
that days-to-time uses a different epoch from time-to-days.  The fix was
pretty easy . . . and then I discovered all the code that depends on the
existing behavior.  So I offer the following modest documentation patch,
in the hope that others will be spared any similar confusion.

					-- Bob Rogers
					   http://www.rgrjr.com/


[-- Attachment #2: Type: text/x-patch, Size: 1813 bytes --]

diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 5400d492f0a..2f6bb4e190c 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -2127,6 +2127,14 @@ Time Calculations
 The operating system limits the range of time and zone values.
 @end defun
 
+@defun days-to-time days
+This is not quite the inverse of the @code{time-to-days} function, as
+it uses the Emacs epoch (instead of the year 1) for historical
+reasons.  To get the inverse, subtract @code{(time-to-days 0)} from
+@var{days}, in which case @code{days-to-time} may return @code{nil} if
+@var{days} is negative.
+@end defun
+
 @defun time-to-day-in-year time-value
 This returns the day number within the year corresponding to @var{time-value},
 assuming the default time zone.
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index 9cbe8e0f53c..786134d8ac5 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -181,7 +181,10 @@ seconds-to-time
 
 ;;;###autoload
 (defun days-to-time (days)
-  "Convert DAYS into a time value."
+  "Convert Emacs-epoch DAYS into a time value.
+Note that this does not use the same epoch as time-to-days; you
+must subtract (time-to-days 0) first to convert, and may get nil
+if the result is before the start."
   ;; FIXME: We should likely just pass `t' to `time-convert'.
   ;; All uses I could find in Emacs, GNU ELPA, and NonGNU ELPA can handle
   ;; any valid time representation as return value.
@@ -243,7 +246,7 @@ time-to-day-in-year
 
 ;;;###autoload
 (defun time-to-days (time)
-  "The absolute date corresponding to TIME, a time value.
+  "The absolute pseudo-Gregorian date for TIME, a time value.
 The absolute date is the number of days elapsed since the imaginary
 Gregorian date Sunday, December 31, 1 BC."
   (let* ((tim (decode-time time))

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

* bug#66502: 30.0.50; [PATCH; DOC] time-to-days and days-to-time use different epochs
  2023-10-12 17:23 bug#66502: 30.0.50; [PATCH; DOC] time-to-days and days-to-time use different epochs Bob Rogers
@ 2023-10-14  9:02 ` Eli Zaretskii
  2023-10-14 14:19   ` Bob Rogers
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2023-10-14  9:02 UTC (permalink / raw)
  To: Bob Rogers; +Cc: 66502-done

> From: Bob Rogers <rogers@rgrjr.com>
> Date: Thu, 12 Oct 2023 10:23:35 -0700
> 
>    Imagine my surprise when converting back using days-to-time gave me
> something almost two millenia in the future.  Of course, the problem was
> that days-to-time uses a different epoch from time-to-days.  The fix was
> pretty easy . . . and then I discovered all the code that depends on the
> existing behavior.  So I offer the following modest documentation patch,
> in the hope that others will be spared any similar confusion.

Thanks, installed on the emacs-29 branch, and closing the bug.

Please in the future accompany the patches by a ChangeLog-style commit
log message, it makes the patches easier to install.





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

* bug#66502: 30.0.50; [PATCH; DOC] time-to-days and days-to-time use different epochs
  2023-10-14  9:02 ` Eli Zaretskii
@ 2023-10-14 14:19   ` Bob Rogers
  2023-10-14 15:38     ` Eli Zaretskii
  2023-10-16  2:02     ` Richard Stallman
  0 siblings, 2 replies; 6+ messages in thread
From: Bob Rogers @ 2023-10-14 14:19 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 66502-done

   From: Eli Zaretskii <eliz@gnu.org>
   Date: Sat, 14 Oct 2023 12:02:10 +0300

   Thanks, installed on the emacs-29 branch, and closing the bug.

   Please in the future accompany the patches by a ChangeLog-style commit
   log message, it makes the patches easier to install.

Oops; I didn't do that, because I thought doc patches didn't need a
ChangeLog message.  In hindsight, they need at least a commit message,
so that was pretty silly.

					-- Bob





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

* bug#66502: 30.0.50; [PATCH; DOC] time-to-days and days-to-time use different epochs
  2023-10-14 14:19   ` Bob Rogers
@ 2023-10-14 15:38     ` Eli Zaretskii
  2023-10-16  2:02     ` Richard Stallman
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2023-10-14 15:38 UTC (permalink / raw)
  To: Bob Rogers; +Cc: 66502-done

> From: Bob Rogers <rogers@rgrjr.com>
> Date: Sat, 14 Oct 2023 07:19:46 -0700
> CC: 66502-done@debbugs.gnu.org
> 
>    From: Eli Zaretskii <eliz@gnu.org>
>    Date: Sat, 14 Oct 2023 12:02:10 +0300
> 
>    Thanks, installed on the emacs-29 branch, and closing the bug.
> 
>    Please in the future accompany the patches by a ChangeLog-style commit
>    log message, it makes the patches easier to install.
> 
> Oops; I didn't do that, because I thought doc patches didn't need a
> ChangeLog message.  In hindsight, they need at least a commit message,
> so that was pretty silly.

Yes.  What happened isn't a catastrophe: I typed the message for you.
It just takes more time and more manual work, so is best avoided.

TIA





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

* bug#66502: 30.0.50; [PATCH; DOC] time-to-days and days-to-time use different epochs
  2023-10-14 14:19   ` Bob Rogers
  2023-10-14 15:38     ` Eli Zaretskii
@ 2023-10-16  2:02     ` Richard Stallman
  2023-10-16  5:39       ` Bob Rogers
  1 sibling, 1 reply; 6+ messages in thread
From: Richard Stallman @ 2023-10-16  2:02 UTC (permalink / raw)
  To: Bob Rogers; +Cc: eliz, 66502-done

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > Oops; I didn't do that, because I thought doc patches didn't need a
  > ChangeLog message.  In hindsight, they need at least a commit message,
  > so that was pretty silly.

the commit message should list what entities you changed, added or
deleted: that is, the doc strings of which functions or variables etc.
And, in a general sense, what the change was about.

Please look at doc string change logs in some of the principal files.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







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

* bug#66502: 30.0.50; [PATCH; DOC] time-to-days and days-to-time use different epochs
  2023-10-16  2:02     ` Richard Stallman
@ 2023-10-16  5:39       ` Bob Rogers
  0 siblings, 0 replies; 6+ messages in thread
From: Bob Rogers @ 2023-10-16  5:39 UTC (permalink / raw)
  To: rms; +Cc: eliz, 66502-done

   From: Richard Stallman <rms@gnu.org>
   Date: Sun, 15 Oct 2023 22:02:57 -0400

   [[[ To any NSA and FBI agents reading my email: please consider    ]]]
   [[[ whether defending the US Constitution against all enemies,     ]]]
   [[[ foreign or domestic, requires you to follow Snowden's example. ]]]

     > Oops; I didn't do that, because I thought doc patches didn't need a
     > ChangeLog message.  In hindsight, they need at least a commit message,
     > so that was pretty silly.

   the commit message should list what entities you changed, added or
   deleted: that is, the doc strings of which functions or variables etc.
   And, in a general sense, what the change was about.

   Please look at doc string change logs in some of the principal files.

Thank you, Richard; I realize what I should have done, and how I should
have done it, I just spaced out in this instance.

					-- Bob





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

end of thread, other threads:[~2023-10-16  5:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 17:23 bug#66502: 30.0.50; [PATCH; DOC] time-to-days and days-to-time use different epochs Bob Rogers
2023-10-14  9:02 ` Eli Zaretskii
2023-10-14 14:19   ` Bob Rogers
2023-10-14 15:38     ` Eli Zaretskii
2023-10-16  2:02     ` Richard Stallman
2023-10-16  5:39       ` Bob Rogers

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