Function: parse-time-string
parse-time-string is an autoloaded and byte-compiled function defined
in parse-time.el.gz.
Signature
(parse-time-string STRING)
Documentation
Parse the time in STRING into (SEC MIN HOUR DAY MON YEAR DOW DST TZ).
STRING should be an ISO 8601 time string, e.g., "2020-01-15T16:12:21-08:00",
or something resembling an RFC 822 (or later) date-time, e.g.,
"Wed, 15 Jan 2020 16:12:21 -0800". This function is
somewhat liberal in what format it accepts, and will attempt to
return a "likely" value even for somewhat malformed strings.
The values returned are identical to those of decode-time, but
any unknown values other than DST are returned as nil, and an
unknown DST value is returned as -1.
Probably introduced at or before Emacs version 27.1.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/parse-time.el.gz
;;;###autoload(put 'parse-time-rules 'risky-local-variable t)
;;;###autoload
(defun parse-time-string (string)
"Parse the time in STRING into (SEC MIN HOUR DAY MON YEAR DOW DST TZ).
STRING should be an ISO 8601 time string, e.g., \"2020-01-15T16:12:21-08:00\",
or something resembling an RFC 822 (or later) date-time, e.g.,
\"Wed, 15 Jan 2020 16:12:21 -0800\". This function is
somewhat liberal in what format it accepts, and will attempt to
return a \"likely\" value even for somewhat malformed strings.
The values returned are identical to those of `decode-time', but
any unknown values other than DST are returned as nil, and an
unknown DST value is returned as -1."
(condition-case ()
(iso8601-parse string)
(wrong-type-argument
(let ((time (list nil nil nil nil nil nil nil -1 nil))
(temp (parse-time-tokenize (downcase string))))
(while temp
(let ((parse-time-elt (pop temp))
(rules parse-time-rules)
(exit nil))
(while (and rules (not exit))
(let* ((rule (pop rules))
(slots (pop rule))
(predicate (pop rule))
(parse-time-val))
(when (and (not (nth (car slots) time)) ;not already set
(setq parse-time-val
(cond ((and (consp predicate)
(not (functionp predicate)))
(and (numberp parse-time-elt)
(<= (car predicate) parse-time-elt)
(or (not (cdr predicate))
(<= parse-time-elt
(cadr predicate)))
parse-time-elt))
((symbolp predicate)
(cdr (assoc parse-time-elt
(symbol-value predicate))))
((funcall predicate)))))
(setq exit t)
(while slots
(let ((new-val (if rule
(let ((this (pop rule)))
(if (vectorp this)
(cl-parse-integer
parse-time-elt
:start (aref this 0)
:end (aref this 1))
(funcall this)))
parse-time-val)))
(setf (nth (pop slots) time) new-val))))))))
time))))