Function: org-get-time-of-day
org-get-time-of-day is a byte-compiled function defined in
org-agenda.el.gz.
Signature
(org-get-time-of-day S &optional STRING)
Documentation
Check string S for a time of day.
If found, return it as a military time number between 0 and 2400. If not found, return nil.
The optional STRING argument forces conversion into a 5 character wide string
HH:MM. When it is overtime, any time above 24:00 is turned into "+H:MM"
where H:MM is the duration above midnight.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-agenda.el.gz
(defun org-get-time-of-day (s &optional string)
"Check string S for a time of day.
If found, return it as a military time number between 0 and 2400.
If not found, return nil.
The optional STRING argument forces conversion into a 5 character wide string
HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
where H:MM is the duration above midnight."
(let ((case-fold-search t)
(time-regexp
(rx word-start
(group (opt (any "012")) digit) ;group 1: hours
(or (and ":" (group (any "012345") digit) ;group 2: minutes
(opt (group (or "am" "pm")))) ;group 3: am/pm
;; Special "HHam/pm" case.
(group-n 3 (or "am" "pm")))
word-end)))
(save-match-data
(when (and (string-match time-regexp s)
(not (eq 'org-link (get-text-property 1 'face s))))
(let ((hours
(let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
(am-p (equal ampm "am")))
(pcase (string-to-number (match-string 1 s))
((and (guard (not ampm)) h) h)
(12 (if am-p 0 12))
(h (+ h (if am-p 0 12))))))
(minutes
(if (match-end 2)
(string-to-number (match-string 2 s))
0)))
(pcase string
(`nil (+ minutes (* hours 100)))
((and `overtime
(guard (or (> hours 24)
(and (= hours 24)
(> minutes 0)))))
(format "+%d:%02d" (- hours 24) minutes))
((guard org-agenda-time-leading-zero)
(format "%02d:%02d" hours minutes))
(_
(format "%d:%02d" hours minutes))))))))