Function: diary-icalendar-format-rrule-sexp

diary-icalendar-format-rrule-sexp is a byte-compiled function defined in diary-icalendar.el.gz.

Signature

(diary-icalendar-format-rrule-sexp COMPONENT)

Documentation

Format the recurrence rule data in COMPONENT as a diary S-expression.

The returned string looks like "%%(diary-rrule ...)", and contains the necessary data from COMPONENT for the calendar to compute recurrences of the event.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/diary-icalendar.el.gz
(defun di:format-rrule-sexp (component)
  "Format the recurrence rule data in COMPONENT as a diary S-expression.

The returned string looks like \"%%(diary-rrule ...)\", and contains the
necessary data from COMPONENT for the calendar to compute recurrences of
the event."
  (ical:with-component component
      ((ical:dtstart :value dtstart)
       (ical:dtend :value dtend)
       (ical:duration :value duration)
       (ical:rrule :value rrule)
       (ical:rdate :all rdate-nodes)
       (ical:exdate :all exdate-nodes))
    (unless (or rrule rdate-nodes)
      (di:signal-import-error "No recurrence data in component"))
    (let ((exdates
           (mapcar #'ical:ast-node-value
                   (apply #'append
                          (mapcar #'ical:ast-node-value exdate-nodes))))
          (rdates
           (mapcar #'ical:ast-node-value
                   (apply #'append
                          (mapcar #'ical:ast-node-value rdate-nodes))))
          ;; N.B. we intentionally *don't* add any clock times to the
          ;; imported diary entry, since they could conflict with the
          ;; times generated by the recurrence rule, e.g. if the rule is
          ;; an 'HOURLY rule.  Instead we always specify the end time
          ;; (if any) via a duration, and take care of displaying the
          ;; correct clocks times after computing recurrences during
          ;; diary display (see `diary-rrule').
          (dur-value (cond (duration duration)
                           (dtend (unless (equal dtstart dtend)
                                    (ical:duration-between dtstart dtend)))
                           (t nil)))
          (arg-plist nil))

      (when exdates
        (setq arg-plist (plist-put arg-plist :exclude `(quote ,exdates))))
      (when rdates
        (setq arg-plist (plist-put arg-plist :include `(quote ,rdates))))
      (when dtstart
        (setq arg-plist (plist-put arg-plist :start `(quote ,dtstart))))
      (when dur-value
        (setq arg-plist (plist-put arg-plist :duration `(quote ,dur-value))))
      (when rrule
        ;; TODO: make this prettier to look at?
        (setq arg-plist (append (list :rule `(quote ,rrule)) arg-plist)))
      ;; TODO: timezones??

      (setq arg-plist (cons 'diary-rrule arg-plist))
      (string-trim ; removing trailing \n added by pp
       (concat diary-sexp-entry-symbol
               (with-output-to-string (pp arg-plist)))))))