[icalendar-dev] feature suggestion & patch
Matt Chisholm
matt-icalendar at mosuki.com
Mon Nov 6 07:27:06 CET 2006
Hi all. I'm using the icalendar package to convert iCalendar files
into an internal database that's not too different than iCalendar.
Any program that wants to calculate recurring event dates basically
has to perform the parsing done in vWeekday.__init__() in prop.py on
'BYDAY' fields of 'RRULE' properties. This method uses the regular
expression WEEKDAY_RULE to turn strings like '1SU' or '-2FR' into
structured representations that mean repetitions like "first sunday"
or "second to last friday".
Rather than duplicate this work internally in our program, it seems to
make more sense to modify the vWeekday object to store the results of
this parsing. The value has to be parsed to make sure it's valid
iCalendar format anyway, but vWeekday.__init__() throws away the
results of the parse.
So, here's a patch that modifies vWeekday.__init__() to store the
results of parsing the string values of BYDAY fields on the vWeekday
object.
-matt
-------------- next part --------------
Index: src/icalendar/prop.py
===================================================================
--- src/icalendar/prop.py (revision 34254)
+++ src/icalendar/prop.py (working copy)
@@ -754,7 +754,12 @@
relative = match['relative']
if not weekday in vWeekday.week_days or sign not in '+-':
raise ValueError, 'Expected weekday abbrevation, got: %s' % self
+ self.weekday_number = vWeekday.week_days[weekday]
self.relative = relative and int(relative) or None
+ if self.relative:
+ self.offset_number = int(relative)
+ if sign == '-':
+ self.offset_number *= -1
self.params = Parameters()
def ical(self):
More information about the icalendar-dev
mailing list