From 6c55891b5850c923196187b21b73f52d474c325a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulrich=20M=C3=BCller?= 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