0

I'd like to create a capture template that automatically schedules the date for the upcoming Friday (if today is a Tuesday, Wednesday, Thursday) or for the upcoming Tuesday (if today is a Friday, Saturday, Sunday, or Monday).

Any ideas are much appreciated.

SaMeji
  • 104
  • 6

2 Answers2

2

Another way to do this is to determine the closest day of the week after today and send it to the org-read-date function.

(defun schedule-next-tuesday-or-friday ()
  (let* ((dow (format-time-string "%a" (current-time)))
         (future-dow (pcase dow
                       ((or "Sat" "Sun" "Mon") "Tue")
                       (_ "Fri"))))
    (format-time-string (car org-time-stamp-formats)
                        (org-read-date nil t future-dow))))

In the template add:

\nSCHEDULED: %(schedule-next-tuesday-or-friday)

The %(sexp) is evaluated and replaced with the result. See org-capture-templates for more information.

jagrg
  • 3,824
  • 4
  • 19
1

Here's an interesting solution to the "next Tuesday" issue. Note that it uses gnu date function.

your next schedule date-time:

(defun schedule-next-friday-or-tuesday(&optional ti)
  (setq dowt (string-to-number (format-time-string "%w" (if ti ti (current-time)))))
  ;;(setq dowt 2)
  (setq human-time (if(and (>= dowt 2) (<= dowt 4))
                       "next Friday"
                     "next Tuesday"))

  (parse-time-string (with-temp-buffer
                       (call-process "env" nil t nil "LC_ALL=C" "LANGUAGE=" "date" "-d" human-time)
                       (or (bobp) (delete-backward-char 1))
                       (buffer-string))))

(schedule-next-friday-or-tuesday)
RichieHH
  • 848
  • 4
  • 9