diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-12-04 10:33:32 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-12-04 10:36:07 -0800 |
commit | 63be97fb050545cc33ae5d857188ad45fbe27715 (patch) | |
tree | 8a85954020012b2a0c467f262d5be51961b4c52c /lisp/calendar/time-date.el | |
parent | 7384a329d2582e28e28eb8f8e568f7688dceea38 (diff) | |
download | emacs-63be97fb050545cc33ae5d857188ad45fbe27715.tar.gz |
Fix (date-to-time "2021-12-04")
This should complete the fix for Bug#52209.
* lisp/calendar/time-date.el (date-to-time): Apply
decoded-time-set-defaults only to the output of (parse-time-string
date), and only when the output has a year (to avoid confusion
when dates lack years). There is no point applying it after
timezone-make-date-arpa-standard since the latter fills in all the
blanks. And the former code mistakenly called encode-time on an
already-encoded time. This goes back to the code a couple of days
ago, except with changed behavior (to fix Bug#52209) only when
timezone-make-date-arpa-standard is not called.
* test/lisp/calendar/time-date-tests.el (test-date-to-time)
(test-days-between): New tests.
Diffstat (limited to 'lisp/calendar/time-date.el')
-rw-r--r-- | lisp/calendar/time-date.el | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index 8a6ee0f2702..37a16d3b98c 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el @@ -153,28 +153,22 @@ 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." - ;; 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 - (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) - ;; 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))))))))))) + (condition-case err + (let ((parsed (parse-time-string date))) + (when (decoded-time-year parsed) + (decoded-time-set-defaults parsed)) + (encode-time parsed)) + (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))))))))) ;;;###autoload (defalias 'time-to-seconds 'float-time) |