我一直在开发一个基于事件的 AJAX 应用程序,该应用程序以下列格式(Django 模型)将重复事件存储在表中:
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)
rec_type 以以下格式存储数据:
[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.
例如:
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
这工作正常,并允许简洁地传输许多事件,但我现在需要提取在给定范围内发生的所有事件。例如,在特定的日期、星期或月份,我对如何最好地接近有点迷茫。
特别是,我被困在如何检查具有给定重复模式的事件是否有资格出现在结果中。
这里最好的方法是什么?