Function: org-element-timestamp-parser
org-element-timestamp-parser is a byte-compiled function defined in
org-element.el.gz.
Signature
(org-element-timestamp-parser)
Documentation
Parse time stamp at point, if any.
When at a time stamp, return a new syntax node of timestamp type
containing :type, :range-type, :raw-value, :year-start,
:month-start, :day-start, :hour-start, :minute-start,
:year-end, :month-end, :day-end, :hour-end, :minute-end,
:repeater-type, :repeater-value, :repeater-unit,
:repeater-deadline-value, :repeater-deadline-unit, :warning-type,
:warning-value, :warning-unit, :diary-sexp, :begin, :end and
:post-blank properties. Otherwise, return nil.
Assume point is at the beginning of the timestamp.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
(defun org-element-timestamp-parser ()
"Parse time stamp at point, if any.
When at a time stamp, return a new syntax node of `timestamp' type
containing `:type', `:range-type', `:raw-value', `:year-start',
`:month-start', `:day-start', `:hour-start', `:minute-start',
`:year-end', `:month-end', `:day-end', `:hour-end', `:minute-end',
`:repeater-type', `:repeater-value', `:repeater-unit',
`:repeater-deadline-value', `:repeater-deadline-unit', `:warning-type',
`:warning-value', `:warning-unit', `:diary-sexp', `:begin', `:end' and
`:post-blank' properties. Otherwise, return nil.
Assume point is at the beginning of the timestamp."
(when (looking-at-p org-element--timestamp-regexp)
(save-excursion
(let* ((begin (point))
(activep (eq (char-after) ?<))
(raw-value
(progn
(looking-at org-element--timestamp-raw-value-regexp)
(match-string-no-properties 0)))
(diaryp (match-beginning 2))
diary-sexp
(date-start (if diaryp
;; Only consider part after sexp for
;; diary timestamps.
(save-match-data
(looking-at org-element--timestamp-regexp)
(setq diary-sexp
(buffer-substring-no-properties
(+ 3 (match-beginning 0))
(match-beginning 2)))
(match-string 2))
(match-string-no-properties 1)))
(date-end (match-string-no-properties 3))
(post-blank (progn (goto-char (match-end 0))
(skip-chars-forward " \t")))
(end (point))
(time-range
(when (string-match
"[012]?[0-9]:[0-5][0-9]\\(-\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)"
date-start)
(cons (string-to-number (match-string 2 date-start))
(string-to-number (match-string 3 date-start)))))
(type (cond (diaryp 'diary)
((and activep (or date-end time-range)) 'active-range)
(activep 'active)
((or date-end time-range) 'inactive-range)
(t 'inactive)))
(range-type (cond
(date-end 'daterange)
(time-range 'timerange)
(t nil)))
(repeater-props
(and (not diaryp)
(string-match
(rx
(group-n 1 (or "+" "++" ".+"))
(group-n 2 (+ digit))
(group-n 3 (any "hdwmy"))
(optional
"/"
(group-n 4 (+ digit))
(group-n 5 (any "hdwmy"))))
raw-value)
(nconc
(list
:repeater-type
(let ((type (match-string 1 raw-value)))
(cond ((equal "++" type) 'catch-up)
((equal ".+" type) 'restart)
(t 'cumulate)))
:repeater-value (string-to-number (match-string 2 raw-value))
:repeater-unit
(pcase (string-to-char (match-string 3 raw-value))
(?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))
(let ((repeater-deadline-value (match-string 4 raw-value))
(repeater-deadline-unit (match-string 5 raw-value)))
(when (and repeater-deadline-value repeater-deadline-unit)
(list
:repeater-deadline-value (string-to-number repeater-deadline-value)
:repeater-deadline-unit
(pcase (string-to-char repeater-deadline-unit)
(?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year))))))))
(warning-props
(and (not diaryp)
(string-match "\\(-\\)?-\\([0-9]+\\)\\([hdwmy]\\)" raw-value)
(list
:warning-type (if (match-string 1 raw-value) 'first 'all)
:warning-value (string-to-number (match-string 2 raw-value))
:warning-unit
(pcase (string-to-char (match-string 3 raw-value))
(?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))))
year-start month-start day-start hour-start minute-start year-end
month-end day-end hour-end minute-end)
;; Parse date-start.
(unless diaryp
(let ((date (org-parse-time-string date-start t)))
(setq year-start (nth 5 date)
month-start (nth 4 date)
day-start (nth 3 date)
hour-start (nth 2 date)
minute-start (nth 1 date))))
;; Compute date-end. It can be provided directly in timestamp,
;; or extracted from time range. Otherwise, it defaults to the
;; same values as date-start.
(unless diaryp
(let ((date (and date-end (org-parse-time-string date-end t))))
(setq year-end (or (nth 5 date) year-start)
month-end (or (nth 4 date) month-start)
day-end (or (nth 3 date) day-start)
hour-end (or (nth 2 date) (car time-range) hour-start)
minute-end (or (nth 1 date) (cdr time-range) minute-start))))
;; Diary timestamp with time.
(when (and diaryp
(string-match "\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\(-\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)?" date-start))
(setq hour-start (match-string 1 date-start)
minute-start (match-string 2 date-start)
hour-end (match-string 4 date-start)
minute-end (match-string 5 date-start))
(when hour-start (setq hour-start (string-to-number hour-start)))
(when minute-start (setq minute-start (string-to-number minute-start)))
(when hour-end (setq hour-end (string-to-number hour-end)))
(when minute-end (setq minute-end (string-to-number minute-end))))
(org-element-create
'timestamp
(nconc (list :type type
:range-type range-type
:raw-value raw-value
:year-start year-start
:month-start month-start
:day-start day-start
:hour-start hour-start
:minute-start minute-start
:year-end year-end
:month-end month-end
:day-end day-end
:hour-end hour-end
:minute-end minute-end
:begin begin
:end end
:post-blank post-blank)
(and diary-sexp (list :diary-sexp diary-sexp))
repeater-props
warning-props))))))