From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bob Rogers Newsgroups: gmane.emacs.bugs Subject: bug#66502: 30.0.50; [PATCH; DOC] time-to-days and days-to-time use different epochs Date: Thu, 12 Oct 2023 10:23:35 -0700 Message-ID: <25896.11159.190340.117173@orion.rgrjr.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="L+EZYRGrEa" Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40500"; mail-complaints-to="usenet@ciao.gmane.io" To: 66502@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 12 19:25:01 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qqzQj-000AHe-1r for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 12 Oct 2023 19:25:01 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqzQS-0002AT-1k; Thu, 12 Oct 2023 13:24:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqzQP-0002AH-Kt for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 13:24:41 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqzQO-0003Pb-Iq for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 13:24:41 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qqzQk-0004rw-MD for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 13:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Bob Rogers Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Oct 2023 17:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66502 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.169713145218643 (code B ref -1); Thu, 12 Oct 2023 17:25:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Oct 2023 17:24:12 +0000 Original-Received: from localhost ([127.0.0.1]:44223 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqzPw-0004qd-3L for submit@debbugs.gnu.org; Thu, 12 Oct 2023 13:24:12 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:33880) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqzPs-0004qO-Qb for submit@debbugs.gnu.org; Thu, 12 Oct 2023 13:24:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqzPQ-0001Dv-Rx for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 13:23:41 -0400 Original-Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqzPO-0003Kz-Q9 for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 13:23:40 -0400 Original-Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-278f0f565e2so957833a91.2 for ; Thu, 12 Oct 2023 10:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rgrjr-com.20230601.gappssmtp.com; s=20230601; t=1697131417; x=1697736217; darn=gnu.org; h=subject:to:date:message-id:content-transfer-encoding:mime-version :from:from:to:cc:subject:date:message-id:reply-to; bh=p8we1ats35y/ZmiPVtRRof27ef98g9EGdmRtc/i6Wm8=; b=bO8Ybj0me6wb6l28llDEZKvHaPIMLmOB9ZGhKgZsal7mpxNssCp7mvIKBgOfdCxprK 3i4AI4zJJj3T6i1d1dhTgSOWuYdWkF/sMMj5wz7CObWk8tfM+Kyyb3L05IlQauWdzOEi Q8Q9XZgp0OCvg5bMDO/2BVcUHhbAdObFXZNYE7UHTdKSq0+J54WWefAMteIBO9UtauE2 jA45317oWX8H+OiokACs7pYTx+cGmlpP/Z+PmcjJdtP5yOyALsVuCQPLlGiGW1JfgFEc SqKrwky6vYkFXuoYxiNPWmKbQmqsZnOROv+IOq6TzjOyHplJ2+XT173+lMHlAIUpJCqC WYQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697131417; x=1697736217; h=subject:to:date:message-id:content-transfer-encoding:mime-version :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=p8we1ats35y/ZmiPVtRRof27ef98g9EGdmRtc/i6Wm8=; b=L4k+03VFFpGepz8/VTwj3USL51lQmSCQeyrXX4kU2Ut082Vw9yXxj6PYpAtfuQ8kjM BE/dYK03Rag3mCoon0sDyYAbqxtv23FddewsfMkv4QDvFw9lBhawdUVCLgbhdokc7VLT OLiKZRtZ0qFW42tEHqS/w5O+ib5KxkeAu60Kk7ruPM5eK+mqpkGtdCnXqWTWcPJ6axVZ cyedSFZD6mzCZM0IgrNRmiJTLVFMaYVcPVwZnhg6djabTR6xhlwAMule9qHooLwin0E5 fEFvIaMT4MQYB3dnZeRATOTDebrFGLPnHpuQ/RWDyroMQs5oqrfggIIFxBIVbX5Ihxs7 p6pg== X-Gm-Message-State: AOJu0Yxi2z3Nzm5d04jCux7e+9+UPbIksYeMHKTKXtCeP2vsGYJjLvK3 Q5GfAjGXM9ki0cwfOo8w4OJrQA== X-Google-Smtp-Source: AGHT+IGttiyTU7qn772k2OQOl1ekezp4uod6wAJ2Pf15n6VNeuqkSSBqfILM/xg7SKCjZjR5ISfBLg== X-Received: by 2002:a17:90b:1b50:b0:274:8041:94c with SMTP id nv16-20020a17090b1b5000b002748041094cmr21580026pjb.13.1697131416678; Thu, 12 Oct 2023 10:23:36 -0700 (PDT) Original-Received: from orion.rgrjr.com ([2600:1700:7c2c:e000::22]) by smtp.gmail.com with ESMTPSA id 28-20020a17090a001c00b0027d0af2e9c3sm2272839pja.40.2023.10.12.10.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 10:23:36 -0700 (PDT) X-Mailer: VM 8.2.0b under 30.0.50 (x86_64-pc-linux-gnu) Received-SPF: none client-ip=2607:f8b0:4864:20::1034; envelope-from=rogers@rgrjr.com; helo=mail-pj1-x1034.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272312 Archived-At: --L+EZYRGrEa Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit 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/ --L+EZYRGrEa Content-Type: text/x-patch; name="rgr-days-to-time-doc-1.patch" Content-Description: Content-Disposition: inline; filename="rgr-days-to-time-doc-1.patch" Content-Transfer-Encoding: 7bit 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)) --L+EZYRGrEa--