Function: icalendar-recur-refine-bymonth

icalendar-recur-refine-bymonth is a byte-compiled function defined in icalendar-recur.el.gz.

Signature

(icalendar-recur-refine-bymonth INTERVAL MONTHS &optional VTIMEZONE)

Documentation

Resolve INTERVAL into a list of subintervals matching MONTHS.

MONTHS should be a list of values from a recurrence rule's BYMONTH=... clause; see icalendar-recur for the possible values.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar-recur.el.gz
(defun icr:refine-bymonth (interval months &optional vtimezone)
  "Resolve INTERVAL into a list of subintervals matching MONTHS.

MONTHS should be a list of values from a recurrence rule's
BYMONTH=... clause; see `icalendar-recur' for the possible values."
  (let* ((sorted-months (sort months))
         (interval-start (icr:interval-low interval))
         (curr-year (decoded-time-year interval-start))
         (interval-end (icr:interval-high interval))
         (end-year (decoded-time-year interval-end))
         (subintervals nil))
    (while curr-year
      ;; For each year in the interval...
      (dolist (m sorted-months)
        ;; ...the subinterval is from the first day of the given month
        ;; to the first day of the next
        (let* ((low (ical:make-date-time :year curr-year :month m :day 1
                                         :hour 0 :minute 0 :second 0
                                         :tz vtimezone))
               (high (ical:date/time-add low :month 1 vtimezone)))

          ;; Clip the subinterval bounds, as above
          (when (ical:date/time< low interval-start)
            (setq low interval-start))
          (when (ical:date/time< interval-end high)
            (setq high interval-end))
          (when (and (ical:date/time<= interval-start low)
                     (ical:date/time< low high)
                     (ical:date/time<= high interval-end))
            (push (icr:make-interval low high) subintervals))))
      (setq curr-year (1+ curr-year))
      (when (<= end-year curr-year)
        ; we're done:
        (setq curr-year nil)))
    (nreverse subintervals)))