Subject: Re: bug#52209: 28.0.60; [PATCH] date-to-time fails on pure dates

From: Katsumi Yamaoka <[email-masked]>
Date: Fri, 03 Dec 2021 14:19:33 +0900

On Wed, 01 Dec 2021 05:17:30 +0100, Lars Ingebrigtsen wrote:
> Bob Rogers <[email-masked]> writes:
>>    In the emacs-28 branch at 0dd3883def:
>>    Imagine my surprise when evaluating
>> 	(days-between "2021-10-22" "2020-09-29")
>> returned zero.

> Thanks, applied to Emacs 29.

This change caused another regression.  Please try:

(current-time-string (date-to-time "Fri, 03-Dec-2021 04:59:52 GMT"))

The function needs to test if `parse-time-string' returns a valid
data as the old version did it with the help of `encode-time'.
A patch is below (where why I do `(setq time ...)' is to silence
the byte compiler).

Thanks.

--- time-date.el~	2021-12-01 22:24:35.006052000 +0000
+++ time-date.el	2021-12-03 05:13:22.832443900 +0000
@@ -158,7 +158,10 @@
   (encode-time
     (decoded-time-set-defaults
       (condition-case err
-          (parse-time-string date)
+          (let ((time (parse-time-string date)))
+            (prog1 time
+              ;; Cause an error if data `parse-time-string' returns is invalid.
+              (setq time (encode-time time))))
         (error
          (let ((overflow-error '(error "Specified time is not representable")))
            (if (or (equal err overflow-error)