vixie-time: Refactor 'interpolate-weekdays'
* src/mcron/vixie-time.scm (interpolate-weekdays): Avoid mutation and add 'range-wday' inner procedure.
This commit is contained in:
parent
9187aeb78f
commit
68be2dd2dd
1 changed files with 11 additions and 18 deletions
|
|
@ -122,27 +122,20 @@
|
||||||
(parse-vixie-subelement sub-element base limit))
|
(parse-vixie-subelement sub-element base limit))
|
||||||
(string-tokenize string (char-set-complement (char-set #\,))))))
|
(string-tokenize string (char-set-complement (char-set #\,))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; Consider there are two lists, one of days in the month, the other of days in
|
|
||||||
;; the week. This procedure returns an augmented list of days in the month with
|
|
||||||
;; weekdays accounted for.
|
|
||||||
|
|
||||||
(define (interpolate-weekdays mday-list wday-list month year)
|
(define (interpolate-weekdays mday-list wday-list month year)
|
||||||
|
"Given a list of days in the month MDAY-LIST and a list of days in the week
|
||||||
|
WDAY-LIST, return an augmented list of days in the month with weekdays
|
||||||
|
accounted for."
|
||||||
(let ((t (localtime 0)))
|
(let ((t (localtime 0)))
|
||||||
(set-tm:mday t 1)
|
(set-tm:mday t 1)
|
||||||
(set-tm:mon t month)
|
(set-tm:mon t month)
|
||||||
(set-tm:year t year)
|
(set-tm:year t year)
|
||||||
(let ((first-day (tm:wday (cdr (mktime t)))))
|
(let ((first-day (tm:wday (cdr (mktime t)))))
|
||||||
(apply append
|
(define (range-wday wday)
|
||||||
mday-list
|
(let* ((first (- wday first-day))
|
||||||
(map (lambda (wday)
|
(first* (if (negative? first) (+ 7 first) first)))
|
||||||
(let ((first (- wday first-day)))
|
(range (1+ first*) 32 7)))
|
||||||
(if (< first 0) (set! first (+ first 7)))
|
(apply append mday-list (map range-wday wday-list)))))
|
||||||
(range (+ 1 first) 32 7)))
|
|
||||||
wday-list)))))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; Return the number of days in a month. Fix up a tm object for the zero'th day
|
;; Return the number of days in a month. Fix up a tm object for the zero'th day
|
||||||
;; of the next month, rationalize the object and extract the day.
|
;; of the next month, rationalize the object and extract the day.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue