From: Bob Rogers Date: Wed, 1 Dec 2021 04:14:26 +0000 (+0100) Subject: Make date-to-time work with date-only date strings X-Git-Tag: emacs-29.0.90~3633^2~5 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ec59a6cb0fa4e8d0848a61bcb424ace7ce2ac922;p=emacs.git Make date-to-time work with date-only date strings * lisp/calendar/time-date.el (date-to-time): Try harder to parse dates with no times (bug#52209). --- diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index 155c34927fd..6407138953c 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el @@ -153,19 +153,25 @@ it is assumed that PICO was omitted and should be treated as zero." "Parse a string DATE that represents a date-time and return a time value. DATE should be in one of the forms recognized by `parse-time-string'. If DATE lacks timezone information, GMT is assumed." - (condition-case err - (encode-time (parse-time-string date)) - (error - (let ((overflow-error '(error "Specified time is not representable"))) - (if (equal err overflow-error) - (signal (car err) (cdr err)) - (condition-case err - (encode-time (parse-time-string - (timezone-make-date-arpa-standard date))) - (error - (if (equal err overflow-error) - (signal (car err) (cdr err)) - (error "Invalid date: %s" date))))))))) + ;; Pass the result of parsing through decoded-time-set-defaults + ;; because encode-time signals if HH:MM:SS are not filled in. + (encode-time + (decoded-time-set-defaults + (condition-case err + (parse-time-string date) + (error + (let ((overflow-error '(error "Specified time is not representable"))) + (if (or (equal err overflow-error) + ;; timezone-make-date-arpa-standard misbehaves if + ;; not given at least HH:MM as part of the date. + (not (string-match ":" date))) + (signal (car err) (cdr err)) + (condition-case err + (parse-time-string (timezone-make-date-arpa-standard date)) + (error + (if (equal err overflow-error) + (signal (car err) (cdr err)) + (error "Invalid date: %s" date))))))))))) ;;;###autoload (defalias 'time-to-seconds 'float-time)