From a0c3efd5ba746c299e1be628f234f35054322fbc Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 31 Dec 2013 09:58:57 +1100 Subject: [PATCH] ical.py: revise BYWEEKNO behaviour. BYWEEKNO used to expand to every day in that week. This doesn't really match the RFC as that say that BYDAY should 'expand' with BYWEEKNO, but I would need it to 'limit'. So what should we do? Choose one day from that week, but which? - first day of the week - same day of the week as DTSTART - same day of the week as the date matching DTSTART in this year? None are really ideal, and hopefully it would always be used with BYDAY. As the last is easy I do that. --- lib/ical.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ical.py b/lib/ical.py index 092bc7e..570b8f6 100644 --- a/lib/ical.py +++ b/lib/ical.py @@ -431,7 +431,7 @@ by['BYYEARDAY'] = byyearday class byweekno: ''' - WEEKNO 0 isn't allowed, and negatives aren't defined in the RFC. + WEEKNO 0 isn't allowed, and negatives aren't defined clearly in the RFC. We allow WEEKNO=0 and -1 to be last week with at least 4 days ''' def __init__(self, list): @@ -476,8 +476,9 @@ class byweekno: st.norm_day() st.set_wday() for d in range(7): - if st.yr == moment.yr: + if st.yr == moment.yr and st.wday == moment.wday: rv.append(copy.copy(st)) + break st.day += 1 st.norm_day() st.set_wday() @@ -633,7 +634,7 @@ def make_dates(start, rr): if 'BYYEARDAY' in rr.bylist or 'BYMONTHDAY' in rr.bylist: act = -1 elif 'BYWEEKNO' in rr.bylist: - act = -1 + xtype = 'WEEKLY' elif 'BYMONTH' in rr.bylist: xtype = 'MONTHLY' else: -- 2.39.5