Function: icalendar-recur-refine-bysecond

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

Signature

(icalendar-recur-refine-bysecond INTERVAL SECONDS &optional VTIMEZONE)

Documentation

Resolve INTERVAL into a list of subintervals matching SECONDS.

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

Source Code

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

SECONDS should be a list of values from a recurrence rule's
BYSECOND=... clause; see `icalendar-recur' for the possible values."
  (let* ((sorted-seconds (sort seconds))
         (interval-start (icr:interval-low interval))
         (interval-end (icr:interval-high interval))
         ;; we use absolute times (in seconds) for the loop variables in
         ;; case the interval crosses the boundary between two observances:
         (curr-dt interval-start)
         (curr-ts (time-convert (encode-time curr-dt) 'integer))
         (end-ts (time-convert (encode-time interval-end) 'integer))
         (subintervals nil))
    (while curr-ts
      ;; For each minute in the interval...
      (dolist (s sorted-seconds)
        ;; ...the subinterval is one second long: the given second
        (let* ((low (ical:date-time-variant curr-dt :second s
                                            :tz vtimezone))
               (high (ical:date/time-add low :second 1 vtimezone)))
          (when (ical:date/time< low interval-start)
            (setq low curr-dt))
          (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-ts (+ curr-ts 60)
            curr-dt (if vtimezone
                               (icr:tz-decode-time curr-ts vtimezone)
                             (ical:date/time-add curr-dt :minute 1)))
      (when (<= end-ts curr-ts)
        ;; we're done:
        (setq curr-ts nil)))
    (nreverse subintervals)))