AboutSummaryRefsLogTreeCommitDiffStats
path: root/src/mcron
diff options
context:
space:
mode:
authorMathieu Lirzin <mthl@gnu.org>2018-04-08 15:57:43 +0200
committerMathieu Lirzin <mthl@gnu.org>2018-04-08 16:07:25 +0200
commit68be2dd2dda3fac06a3233b05e3336fa5e953f9d (patch)
treeaa3bc5f986e070e334bff1b05677f0e1c326ad36 /src/mcron
parent9187aeb78f2237e91ec0bc9b47a3ec46f8bf0382 (diff)
downloadmcron-68be2dd2dda3fac06a3233b05e3336fa5e953f9d.tar.gz
mcron-68be2dd2dda3fac06a3233b05e3336fa5e953f9d.tar.bz2
mcron-68be2dd2dda3fac06a3233b05e3336fa5e953f9d.zip
vixie-time: Refactor 'interpolate-weekdays'
* src/mcron/vixie-time.scm (interpolate-weekdays): Avoid mutation and add 'range-wday' inner procedure.
Diffstat (limited to 'src/mcron')
-rw-r--r--src/mcron/vixie-time.scm29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/mcron/vixie-time.scm b/src/mcron/vixie-time.scm
index 0a39e41..64f0e87 100644
--- a/src/mcron/vixie-time.scm
+++ b/src/mcron/vixie-time.scm
@@ -122,27 +122,20 @@
(parse-vixie-subelement sub-element base limit))
(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)
+ "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)))
- (set-tm:mday t 1)
- (set-tm:mon t month)
- (set-tm:year t year)
+ (set-tm:mday t 1)
+ (set-tm:mon t month)
+ (set-tm:year t year)
(let ((first-day (tm:wday (cdr (mktime t)))))
- (apply append
- mday-list
- (map (lambda (wday)
- (let ((first (- wday first-day)))
- (if (< first 0) (set! first (+ first 7)))
- (range (+ 1 first) 32 7)))
- wday-list)))))
-
-
+ (define (range-wday wday)
+ (let* ((first (- wday first-day))
+ (first* (if (negative? first) (+ 7 first) first)))
+ (range (1+ first*) 32 7)))
+ (apply append mday-list (map range-wday wday-list)))))
;; 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.