bug-mcron
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-mcron] Documentation error (every second sunday)


From: Adam Tack
Subject: [Bug-mcron] Documentation error (every second sunday)
Date: Fri, 11 Jan 2019 20:12:15 +0100

I think that there's an error in the Texinfo page for mcron in the
"Every second Sunday" section:

https://www.gnu.org/software/mcron/manual/mcron.html#Every-second-Sunday

If the first day of the next month is a Sunday, then we should only
*add* 7 days, so that the eighth is also a Sunday.

Hence, the example should be:

#+BEGIN_SRC scheme
(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)
                                 7
                                 (- 14 first-day))))
         (+ next-month (* 24 60 60 second-sunday))))
     "my-program")
#+END_SRC

(Arguably ~second-sunday~ as a variable name is a bit of a misnomer.)

If you wish to test this, to be sure, compare the effect of the (current)
function when finding the second Sunday of August (with July 2, as the
starting time), and the second Sunday of September (with August 2, as
the starting time). (September 1 was a Sunday, while August 1 wasn't.)

#+BEGIN_SRC scheme
(use-modules (mcron job-specifier))

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

;; 2019-07-02 to ensure that it's already July irrespective of the
;; time-zone
(define jul-second 1562025600)
;; 2019-08-02 to ensure that it's already August irrespective of the
;; time-zone
(define aug-second 1564704000)

(strftime "%c" (localtime (second-sunday-of-next-month jul-second)))
;; vs.
(strftime "%c" (localtime (second-sunday-of-next-month aug-second)))

#+END_SRC

Sorry for the unsubstantial bug report, but this was driving me crazy
while I tried to figure out what I wasn't getting (especially as it
was "left as an exercise to the student to understand how this
works").

Trivial patch attached.

Thanks!
Adam

Attachment: texinfo_mcron_patch.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]