]> git.neil.brown.name Git - plato.git/commitdiff
ical.py: revise BYWEEKNO behaviour.
authorNeilBrown <neilb@suse.de>
Mon, 30 Dec 2013 22:58:57 +0000 (09:58 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 30 Dec 2013 22:58:57 +0000 (09:58 +1100)
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

index 092bc7ec8ab85e64ea86ab4873555899ba575e54..570b8f6f6e5473a1447630dd40a5e34c631c1461 100644 (file)
@@ -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: