corresponding Lisp timestamp. The argument @var{string} should represent
a date-time, and should be in one of the forms recognized by
@code{parse-time-string} (see below). This function assumes Universal
-Time if @var{string} lacks explicit time zone information.
+Time if @var{string} lacks explicit time zone information,
+and assumes earliest values if @var{string} lacks month, day, or time.
The operating system limits the range of time and zone values.
@end defun
** New variable 'help-buffer-under-preparation'.
This variable is bound to t during the preparation of a "*Help*" buffer.
++++
+** 'date-to-time' now assumes earliest values if its argument lacks
+month, day, or time. For example, (date-to-time "2021-12-04") now
+assumes a time of 00:00 instead of signaling an error.
\f
* Changes in Emacs 29.1 on Non-Free Operating Systems
"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)
(encode-time-value 1 2 3 4 3))
'(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")))
+
+(ert-deftest test-days-between ()
+ (should (equal (days-between "2021-10-22" "2020-09-29") 388)))
+
(ert-deftest test-leap-year ()
(should-not (date-leap-year-p 1999))
(should-not (date-leap-year-p 1900))