From: Ulrich Mueller <ulm@gentoo.org>
To: 72570@debbugs.gnu.org
Subject: bug#72570: 31.0.50; Regression in date-to-time
Date: Mon, 12 Aug 2024 09:27:11 +0200 [thread overview]
Message-ID: <u4j7q8als@gentoo.org> (raw)
In-Reply-To: <uplqf8mi2@gentoo.org> (Ulrich Mueller's message of "Sun, 11 Aug 2024 10:57:57 +0200")
[-- Attachment #1: Type: text/plain, Size: 966 bytes --]
Attached patch will make date-to-time work as documented.
Alternatively, maybe it would be more consistent with other time
functions in Emacs if date-to-time would use local time as the default
(i.e. what is assumed by the current unit test in time-date-tests.el).
However, the fallback code uses Universal Time, and I don't see an easy
way to modify it for local time. The problem is that
timezone-make-date-arpa-standard would need an explicit timezone as its
second argument, which we don't know. We cannot use (current-time-zone)
there, because it's the timezone of the current time, not the one of the
to-be-converted timestamp. (For example, in the Europe/Berlin timezone,
(current-time-zone) returns (7200 "CEST"), while for conversion of
"2024-01-01 00:00:00" one would need (3600 "CET")).
(BTW, the code in timezone.el is very brittle. For example,
(timezone-make-date-arpa-standard "2024-01-01") signals a
wrong-type-argument error from 'capitalize'.)
[-- Attachment #2: 0001-Make-date-to-time-without-timezone-work-as-documente.patch --]
[-- Type: text/plain, Size: 2301 bytes --]
From 6c55891b5850c923196187b21b73f52d474c325a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ulrich=20M=C3=BCller?= <ulm@gentoo.org>
Date: Mon, 12 Aug 2024 07:30:01 +0200
Subject: [PATCH] Make date-to-time without timezone work as documented
* lisp/calendar/time-date.el (date-to-time): Assume Universal Time
rather than local time when no timezone is specified. (Bug#72570)
* test/lisp/calendar/time-date-tests.el (test-date-to-time):
Update test.
---
lisp/calendar/time-date.el | 5 +++--
test/lisp/calendar/time-date-tests.el | 8 ++++++--
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index eca80f1e8b6..2f3ef0d8b4c 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -156,7 +156,7 @@ date-to-time
(condition-case err
(let ((parsed (parse-time-string date)))
(when (decoded-time-year parsed)
- (decoded-time-set-defaults parsed))
+ (decoded-time-set-defaults parsed t))
(encode-time parsed))
(error
(let ((overflow-error '(error "Specified time is not representable")))
@@ -164,7 +164,8 @@ date-to-time
(signal (car err) (cdr err))
(condition-case err
(encode-time (parse-time-string
- (timezone-make-date-arpa-standard date)))
+ (timezone-make-date-arpa-standard
+ date nil '(0 "UTC"))))
(error
(if (equal err overflow-error)
(signal (car err) (cdr err))
diff --git a/test/lisp/calendar/time-date-tests.el b/test/lisp/calendar/time-date-tests.el
index 6512dd0bd07..d7d39f050b7 100644
--- a/test/lisp/calendar/time-date-tests.el
+++ b/test/lisp/calendar/time-date-tests.el
@@ -42,8 +42,12 @@ test-obsolete-encode-time-value
'(1 2 3 4))))
(ert-deftest test-date-to-time ()
- (should (equal (format-time-string "%F %T" (date-to-time "2021-12-04"))
- "2021-12-04 00:00:00")))
+ (should (equal (format-time-string
+ "%F %T" (date-to-time "2021-12-04") t)
+ "2021-12-04 00:00:00"))
+ (should (equal (format-time-string
+ "%F %T" (date-to-time "2021-12-04 00:00:00 +0100") t)
+ "2021-12-03 23:00:00")))
(ert-deftest test-days-between ()
(should (equal (days-between "2021-10-22" "2020-09-29") 388)))
--
2.45.2
next prev parent reply other threads:[~2024-08-12 7:27 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-11 8:57 bug#72570: 31.0.50; Regression in date-to-time Ulrich Mueller
2024-08-12 7:27 ` Ulrich Mueller [this message]
2024-08-12 8:18 ` Ulrich Mueller
2024-08-12 11:42 ` Eli Zaretskii
2024-08-12 12:51 ` Ulrich Mueller
2024-08-12 13:26 ` Eli Zaretskii
2024-08-12 13:48 ` Ulrich Mueller
2024-08-12 14:30 ` Eli Zaretskii
2024-08-12 22:03 ` Paul Eggert
2024-08-13 5:55 ` Ulrich Mueller
2024-08-13 19:39 ` Paul Eggert
2024-08-13 21:11 ` Ulrich Mueller
2024-08-13 21:19 ` Paul Eggert
2024-08-14 8:12 ` Ulrich Mueller
2024-08-14 14:09 ` Ulrich Mueller
2024-08-15 3:27 ` Paul Eggert
2024-08-15 4:35 ` Ulrich Mueller
2024-08-15 6:26 ` Paul Eggert
2024-08-15 6:45 ` Eli Zaretskii
2024-08-15 7:18 ` Ulrich Mueller
2024-08-15 7:22 ` Eli Zaretskii
2024-08-13 11:15 ` Eli Zaretskii
2024-08-13 15:09 ` Ulrich Mueller
2024-08-13 15:36 ` Eli Zaretskii
2024-08-13 19:59 ` Paul Eggert
2024-08-14 8:37 ` Eli Zaretskii
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=u4j7q8als@gentoo.org \
--to=ulm@gentoo.org \
--cc=72570@debbugs.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).