Function: org-read-date-get-relative
org-read-date-get-relative is a byte-compiled function defined in
org.el.gz.
Signature
(org-read-date-get-relative S TODAY DEFAULT)
Documentation
Check string S for special relative date string.
TODAY and DEFAULT are internal times, for today and for a default.
Return shift list (N what def-flag)
WHAT is "d", "w", "m", or "y" for day, week, month, year.
N is the number of WHATs to shift.
DEF-FLAG is t when a double ++ or -- indicates shift relative to
the DEFAULT date rather than TODAY.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-read-date-get-relative (s today default)
"Check string S for special relative date string.
TODAY and DEFAULT are internal times, for today and for a default.
Return shift list (N what def-flag)
WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
N is the number of WHATs to shift.
DEF-FLAG is t when a double ++ or -- indicates shift relative to
the DEFAULT date rather than TODAY."
(require 'parse-time)
(when (and
;; Force case-insensitive.
(let ((case-fold-search t))
(string-match
(concat
"\\`[ \t]*\\([-+]\\{0,2\\}\\)"
"\\([0-9]+\\)?"
"\\([hdwmy]\\|\\(" (mapconcat 'car parse-time-weekdays "\\|") "\\)\\)?"
"\\([ \t]\\|$\\)") s))
(or (> (match-end 1) (match-beginning 1)) (match-end 4)))
(let* ((dir (if (> (match-end 1) (match-beginning 1))
(string-to-char (substring (match-string 1 s) -1))
?+))
(rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
(n (if (match-end 2) (string-to-number (match-string 2 s)) 1))
(what (if (match-end 3) (match-string 3 s) "d"))
(wday1 (cdr (assoc (downcase what) parse-time-weekdays)))
(date (if rel default today))
(wday (nth 6 (decode-time date)))
delta)
(if wday1
(progn
(setq delta (mod (+ 7 (- wday1 wday)) 7))
(when (= delta 0) (setq delta 7))
(when (= dir ?-)
(setq delta (- delta 7))
(when (= delta 0) (setq delta -7)))
(when (> n 1) (setq delta (+ delta (* (1- n) (if (= dir ?-) -7 7)))))
(list delta "d" rel))
(list (* n (if (= dir ?-) -1 1)) what rel)))))