Next: , Previous: , Up: Extended Guile examples   [Contents][Index]

3.2.3 Every second Sunday

To run my-program on the second Sunday of every month, a Guile script like the following should suffice (it is left as an exercise to the student to understand how this works!)

(job (lambda (current-time)
       (let* ((next-month (next-month-from current-time))
              (first-day (tm:wday (localtime next-month)))
              (second-sunday (if (eqv? first-day 0)
                                 (- 14 first-day))))
         (+ next-month (* 24 60 60 second-sunday))))