Function: diary-icalendar-other-sexp-to-recurrence

diary-icalendar-other-sexp-to-recurrence is a byte-compiled function defined in diary-icalendar.el.gz.

Signature

(diary-icalendar-other-sexp-to-recurrence SEXP)

Documentation

Convert diary SEXP to icalendar-rdate by enumerating its recurrences.

The enumeration starts on the current date and includes recurrences in the next diary-icalendar-export-sexp-enumeration-days days. Returns a list (START COMMENT RDATE), where START is an icalendar-dtstart, COMMENT is an icalendar-comment containing SEXP, and RDATE is an icalendar-rdate containing the enumerated recurrences. If there are no recurrences, (START COMMENT EXDATE) is returned, where START is the current date, and EXDATE is an icalendar-exdate excluding that start date as a recurrence. (This is because icalendar-dtstart is a required property and must be present even if the recurrence set is empty.)

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/diary-icalendar.el.gz
(defun di:other-sexp-to-recurrence (sexp)
  "Convert diary SEXP to `icalendar-rdate' by enumerating its recurrences.

The enumeration starts on the current date and includes recurrences in
the next `diary-icalendar-export-sexp-enumeration-days' days.  Returns a
list (START COMMENT RDATE), where START is an `icalendar-dtstart',
COMMENT is an `icalendar-comment' containing SEXP, and RDATE is an
`icalendar-rdate' containing the enumerated recurrences.  If there are
no recurrences, (START COMMENT EXDATE) is returned, where START is the
current date, and EXDATE is an `icalendar-exdate' excluding that start
date as a recurrence.  (This is because `icalendar-dtstart' is a required
property and must be present even if the recurrence set is empty.)"
  (let* ((today (calendar-absolute-from-gregorian (calendar-current-date)))
         (end (+ today (1- di:export-sexp-enumeration-days)))
        dtstart rdates exdates)
    (dolist (absdate (number-sequence today end))
      (calendar-dlet ((date (calendar-gregorian-from-absolute absdate)))
        (when (eval sexp t)
          (push date rdates))))
    (if rdates
        (progn
          (setq rdates (nreverse rdates))
          (setq dtstart (car rdates)
                rdates (cdr rdates)))
      (ical:warn
       (format "No recurrences in the next %d days: %s"
               di:export-sexp-enumeration-days
               sexp)
       :severity 0)
      ;; When there are no recurrences, we still need a DTSTART, but we
      ;; can exclude it via an EXDATE:
      (setq dtstart (calendar-current-date)
            exdates (list dtstart)))

    (append
     (list
      (ical:make-property ical:dtstart dtstart
        (ical:valuetypeparam 'ical:date))
      ;; TODO: should we maybe use an X-name property for this?
      (ical:make-property ical:comment (format "%s" sexp)))
     (if rdates
         (list
          (ical:make-property ical:rdate rdates
            (ical:valuetypeparam 'ical:date)))
       (list
        (ical:make-property ical:exdate exdates
          (ical:valuetypeparam 'ical:date)))))))