Event Extraction from Recurrence Pattern
<p>I've been working on a event based AJAX application that stores recurring events in the a table in the following format (Django models):</p>

<pre><code>event_id = models.CharField(primary_key=True, max_length=24)
# start_date - the start date of the first event in a series
start_date = models.DateTimeField()
# the end date of the last event in a series
end_date = models.DateTimeField()
# Length of the occurence
event_length = models.BigIntegerField(null=True, blank=True, default=0)
rec_type = models.CharField(max_length=32)
</code></pre>

<p>The rec_type stores data in the following format:</p>

<pre><code>[type]_[count]_[day]_[count2]_[days]#[extra]

type - the type of repeation: 'day','week','month','year'.
count - the interval between events in the “type” units.
day and count2 - define a day of a month ( first Monday, third Friday, etc ).
days - the comma-separated list of affected week days.
extra - the extra info that can be used to change presentation of recurring details.
</code></pre>

<p>For example:</p>

<pre><code>day_3___ - each three days
month _2___ - each two month
month_1_1_2_ - second Monday of each month
week_2___1,5 - Monday and Friday of each second week 
</code></pre>

<p>This works fine, and allows many events to be transmitted concisely, but I now have the requirement to extract all events that occur during a given range. For example on a specific date, week or month and I am a bit lost as to how best to approach. </p>

<p>In particular, I am stuck with how to check if an event with a given recurrence pattern is eligible to be in the results.</p>

<p>What is the best approach here?</p>
