Function: date-to-time

date-to-time is an autoloaded and byte-compiled function defined in time-date.el.gz.

Signature

(date-to-time DATE)

Documentation

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 time zone information, local time is assumed.

View in manual

Probably introduced at or before Emacs version 29.1.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/time-date.el.gz
;;;###autoload
(defun date-to-time (date)
  "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 time zone information, local time is assumed."
  (condition-case err
      ;; Parse DATE. If it contains a year, use defaults for other components.
      ;; Then encode the result; this signals an error if the year is missing,
      ;; because encode-time signals if crucial time components are nil.
      ;; This heuristic uses local time if the string lacks time zone info,
      ;; because encode-time treats a nil time zone as local time.
      (let ((parsed (parse-time-string date)))
	(when (decoded-time-year parsed)
	  (decoded-time-set-defaults parsed))
	(encode-time parsed))
    (error
     (if (equal err '(error "Specified time is not representable"))
	 (signal (car err) (cdr err))
       (error "Invalid date: %s" date)))))