Function: icalendar-rrule-value-p

icalendar-rrule-value-p is a byte-compiled function defined in icalendar-parser.el.gz.

Signature

(icalendar-rrule-value-p VALS)

Documentation

Return non-nil if VALS is an iCalendar recurrence rule value.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar-parser.el.gz
(defun ical:rrule-value-p (vals)
  "Return non-nil if VALS is an iCalendar recurrence rule value."
  (and (listp vals)
       ;; FREQ is always required:
       (assq 'FREQ vals)
       ;; COUNT and UNTIL are mutually exclusive if present:
       (not (and (assq 'COUNT vals) (assq 'UNTIL vals)))
       ;; If BYSETPOS is present, another BYXXX clause must be too:
       (or (not (assq 'BYSETPOS vals))
           (assq 'BYMONTH vals)
           (assq 'BYWEEKNO vals)
           (assq 'BYYEARDAY vals)
           (assq 'BYMONTHDAY vals)
           (assq 'BYDAY vals)
           (assq 'BYHOUR vals)
           (assq 'BYMINUTE vals)
           (assq 'BYSECOND vals))
       (let ((freq (ical:rrule-freq vals))
             (byday (ical:rrule-by* 'BYDAY vals))
             (byweekno (ical:rrule-by* 'BYWEEKNO vals))
             (bymonthday (ical:rrule-by* 'BYMONTHDAY vals))
             (byyearday (ical:rrule-by* 'BYYEARDAY vals)))
         (and
          ;; "The BYDAY rule part MUST NOT be specified with a numeric
          ;; value when the FREQ rule part is not set to MONTHLY or
          ;; YEARLY."
          (or (not (consp (car byday)))
              (memq freq '(MONTHLY YEARLY)))
          ;; "The BYDAY rule part MUST NOT be specified with a numeric
          ;; value with the FREQ rule part set to YEARLY when the
          ;; BYWEEKNO rule part is specified." This also covers:
          ;; "[The BYWEEKNO] rule part MUST NOT be used when the FREQ
          ;; rule part is set to anything other than YEARLY."
          (or (not byweekno)
              (and (eq freq 'YEARLY)
                   (not (consp (car byday)))))
          ;; "The BYMONTHDAY rule part MUST NOT be specified when the
          ;; FREQ rule part is set to WEEKLY."
          (not (and bymonthday (eq freq 'WEEKLY)))
          ;; "The BYYEARDAY rule part MUST NOT be specified when the
          ;; FREQ rule part is set to DAILY, WEEKLY, or MONTHLY."
          (not (and byyearday (memq freq '(DAILY WEEKLY MONTHLY))))))
       ;; check types of all rule parts:
       (seq-every-p
        (lambda (kv)
          (when (consp kv)
            (let* ((keyword (car kv))
                   (val (cadr kv))
                   (type (plist-get ical:-rrule-value-types keyword)))
              (and keyword val type
                   (if (and (consp type)
                            (eq (car type) 'list-of))
                       (ical:list-of-p val (cadr type))
                     (cl-typep val type))))))
         vals)))