Function: org-at-timestamp-p

org-at-timestamp-p is a byte-compiled function defined in org.el.gz.

Signature

(org-at-timestamp-p &optional EXTENDED)

Documentation

Non-nil if point is inside a timestamp.

By default, the function only consider syntactically valid active timestamps. However, the caller may have a broader definition for timestamps. As a consequence, optional argument EXTENDED can be set to the following values

  inactive

    Include also syntactically valid inactive timestamps.

  agenda

    Include timestamps allowed in Agenda, i.e., those in
    properties drawers, planning lines and clock lines.

  lax

    Ignore context. The function matches any part of the
    document looking like a timestamp. This includes comments,
    example blocks...

For backward-compatibility with Org 9.0, every other non-nil value is equivalent to inactive.

When at a timestamp, return the position of the point as a symbol among bracket, after, year, month, hour, minute, day or a number of character from the last know part of the time stamp. If diary sexp timestamps, any point inside the timestamp is considered day (i.e. only bracket, day, and after return values are possible).

When matching, the match groups are the following:
  group 2: year, if any
  group 3: month, if any
  group 4: day number, if any
  group 5: day name, if any
  group 7: hours, if any
  group 8: minutes, if any

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-at-timestamp-p (&optional extended)
  "Non-nil if point is inside a timestamp.

By default, the function only consider syntactically valid active
timestamps.  However, the caller may have a broader definition
for timestamps.  As a consequence, optional argument EXTENDED can
be set to the following values

  `inactive'

    Include also syntactically valid inactive timestamps.

  `agenda'

    Include timestamps allowed in Agenda, i.e., those in
    properties drawers, planning lines and clock lines.

  `lax'

    Ignore context.  The function matches any part of the
    document looking like a timestamp.  This includes comments,
    example blocks...

For backward-compatibility with Org 9.0, every other non-nil
value is equivalent to `inactive'.

When at a timestamp, return the position of the point as a symbol
among `bracket', `after', `year', `month', `hour', `minute',
`day' or a number of character from the last know part of the
time stamp.  If diary sexp timestamps, any point inside the timestamp
is considered `day' (i.e. only `bracket', `day', and `after' return
values are possible).

When matching, the match groups are the following:
  group 2: year, if any
  group 3: month, if any
  group 4: day number, if any
  group 5: day name, if any
  group 7: hours, if any
  group 8: minutes, if any"
  (let* ((regexp
          (if extended
              (if (eq extended 'agenda)
                  (rx-to-string
                   `(or (regexp ,org-ts-regexp3)
                        (regexp ,org-element--timestamp-regexp)))
		org-ts-regexp3)
            org-ts-regexp2))
	 (pos (point))
	 (match?
	  (let ((boundaries (org-in-regexp regexp)))
	    (save-match-data
	      (cond ((null boundaries) nil)
		    ((eq extended 'lax) t)
		    (t
		     (or (and (eq extended 'agenda)
			      (or (org-at-planning-p)
				  (org-at-property-p)
				  (and (bound-and-true-p
					org-agenda-include-inactive-timestamps)
				       (org-at-clock-log-p))))
			 (eq 'timestamp
			     (save-excursion
			       (when (= pos (cdr boundaries)) (forward-char -1))
			       (org-element-type (org-element-context)))))))))))
    (cond
     ((not match?)                        nil)
     ((= pos (match-beginning 0))         'bracket)
     ;; Distinguish location right before the closing bracket from
     ;; right after it.
     ((= pos (1- (match-end 0)))          'bracket)
     ((= pos (match-end 0))               'after)
     ((org-pos-in-match-range pos 2)      'year)
     ((org-pos-in-match-range pos 3)      'month)
     ((org-pos-in-match-range pos 7)      'hour)
     ((org-pos-in-match-range pos 8)      'minute)
     ((or (org-pos-in-match-range pos 4)
	  (org-pos-in-match-range pos 5)) 'day)
     ((and (or (match-end 8) (match-end 5))
           (> pos (or (match-end 8) (match-end 5)))
	   (< pos (match-end 0)))
      (- pos (or (match-end 8) (match-end 5))))
     (t                                   'day))))