Function: icalendar-start-of-weekno
icalendar-start-of-weekno is a byte-compiled function defined in
icalendar-utils.el.gz.
Signature
(icalendar-start-of-weekno WEEKNO YEAR &optional WEEKSTART)
Documentation
Return the start of the WEEKNOth week in the (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). The returned value is an icalendar-date.
If WEEKNO is negative, it refers to the WEEKNOth week before the end of the year: -1 is the last week of the year, -2 second to last, etc.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/icalendar-utils.el.gz
(defun ical:start-of-weekno (weekno year &optional weekstart)
"Return the start of the WEEKNOth week in the (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). The returned value is an `icalendar-date'.
If WEEKNO is negative, it refers to the WEEKNOth week before the end of
the year: -1 is the last week of the year, -2 second to last, etc."
(calendar-gregorian-from-absolute
(+
(* 7 (if (< 0 weekno)
(1- weekno)
(+ 1 weekno (ical:number-of-weeks year weekstart))))
(calendar-dayname-on-or-before
(or weekstart 1)
;; Three days after Jan 1. gives us the nearest occurrence;
;; see `calendar-dayname-on-or-before'
(+ 3 (calendar-absolute-from-gregorian (list 1 1 year)))))))