diff options
| author | Bob Rogers | 2021-12-01 05:14:26 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-12-01 05:14:26 +0100 |
| commit | ec59a6cb0fa4e8d0848a61bcb424ace7ce2ac922 (patch) | |
| tree | ba846070bb6da4c109927ae0873183edea557082 | |
| parent | e2637beb286d8fcc2775b0692494cfade5815921 (diff) | |
| download | emacs-ec59a6cb0fa4e8d0848a61bcb424ace7ce2ac922.tar.gz emacs-ec59a6cb0fa4e8d0848a61bcb424ace7ce2ac922.zip | |
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).
| -rw-r--r-- | lisp/calendar/time-date.el | 32 |
1 files changed, 19 insertions, 13 deletions
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." | |||
| 153 | "Parse a string DATE that represents a date-time and return a time value. | 153 | "Parse a string DATE that represents a date-time and return a time value. |
| 154 | DATE should be in one of the forms recognized by `parse-time-string'. | 154 | DATE should be in one of the forms recognized by `parse-time-string'. |
| 155 | If DATE lacks timezone information, GMT is assumed." | 155 | If DATE lacks timezone information, GMT is assumed." |
| 156 | (condition-case err | 156 | ;; Pass the result of parsing through decoded-time-set-defaults |
| 157 | (encode-time (parse-time-string date)) | 157 | ;; because encode-time signals if HH:MM:SS are not filled in. |
| 158 | (error | 158 | (encode-time |
| 159 | (let ((overflow-error '(error "Specified time is not representable"))) | 159 | (decoded-time-set-defaults |
| 160 | (if (equal err overflow-error) | 160 | (condition-case err |
| 161 | (signal (car err) (cdr err)) | 161 | (parse-time-string date) |
| 162 | (condition-case err | 162 | (error |
| 163 | (encode-time (parse-time-string | 163 | (let ((overflow-error '(error "Specified time is not representable"))) |
| 164 | (timezone-make-date-arpa-standard date))) | 164 | (if (or (equal err overflow-error) |
| 165 | (error | 165 | ;; timezone-make-date-arpa-standard misbehaves if |
| 166 | (if (equal err overflow-error) | 166 | ;; not given at least HH:MM as part of the date. |
| 167 | (signal (car err) (cdr err)) | 167 | (not (string-match ":" date))) |
| 168 | (error "Invalid date: %s" date))))))))) | 168 | (signal (car err) (cdr err)) |
| 169 | (condition-case err | ||
| 170 | (parse-time-string (timezone-make-date-arpa-standard date)) | ||
| 171 | (error | ||
| 172 | (if (equal err overflow-error) | ||
| 173 | (signal (car err) (cdr err)) | ||
| 174 | (error "Invalid date: %s" date))))))))))) | ||
| 169 | 175 | ||
| 170 | ;;;###autoload | 176 | ;;;###autoload |
| 171 | (defalias 'time-to-seconds 'float-time) | 177 | (defalias 'time-to-seconds 'float-time) |