christchurch_django / christchurch /

from dateutil import rrule

def search(calendar, start_date, end_date):
    Searches a vobject calendar for events starting between the specified
    datetime objects, hanlding recurring events as necessary.

    Returns a list of 2 tuples containing (datetime/date of event, vevent object)
    # First, do a pre run to get all the dates we nned to exclude,
    # i.e. those that have specific instances, identified by recurrence-id

    exclusions = []
    for v in calendar.vevent_list:
        rc = v.contents.get('recurrence-id', None)
        if rc is not None:
            # rc is a list, don't know if it can ever contain more than one
            # item, but we'll deal with that anyway.
            for d in rc:

    events = []
    for v in calendar.vevent_list:
        if not hasattr(v, 'rrule'):
            # No recurrence, just look at dtstart
            dt = v.dtstart.value
            if not hasattr(dt, 'date'):
                # A 'date', not 'datetime', can't compare to timezone aware
                # 'datetime'
                if dt >= and dt <=
                    events.append((dt, v))
                if dt >= start_date and dt <= end_date:
                    events.append((dt, v))
            ruleset = rrule.rruleset()
            rule = rrule.rrulestr(v.rrule.value, dtstart=v.dtstart.value)
            if hasattr(v, 'exdate_list'):
                for l in v.exdate_list:
                    for d in l.value:
            for d in exclusions:
            events.extend([(dt, v)
                           for dt in ruleset.between(start_date, end_date)])

    return events
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.