Function: icalendar-number-of-weeks

icalendar-number-of-weeks is a byte-compiled function defined in icalendar-utils.el.gz.

Signature

(icalendar-number-of-weeks YEAR &optional WEEKSTART)

Documentation

Return the number of weeks in (Gregorian) YEAR.

RFC5545 defines week 1 as the first week to include at least four days in the year. Weeks are assumed to start on Monday (= 1) unless WEEKSTART is specified, in which case it should be an integer between 0 (= Sunday) and 6 (= Saturday).

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar-utils.el.gz
(defun ical:number-of-weeks (year &optional weekstart)
  "Return the number of weeks in (Gregorian) YEAR.

RFC5545 defines week 1 as the first week to include at least four days
in the year.  Weeks are assumed to start on Monday (= 1) unless WEEKSTART
is specified, in which case it should be an integer between 0 (= Sunday)
and 6 (= Saturday)."
  ;; There are 53 weeks in a year if Jan 1 is the fourth day after
  ;; WEEKSTART, e.g. if the week starts on Monday and Jan 1 is a
  ;; Thursday, or in a leap year if Jan 1 is the third day after WEEKSTART
  (let* ((jan1wd (calendar-day-of-week (list 1 1 year)))
         (delta (mod (- jan1wd (or weekstart 1)) 7)))
    (if (or (= 4 delta)
            (and (= 3 delta) (calendar-leap-year-p year)))
        53
      52)))