我正在构建一个需要支持重复事件的组日历应用程序,但我提出的处理这些事件的所有解决方案似乎都很简单。我可以限制一个人可以看多远的未来,然后一次性生成所有事件。或者,我可以将事件存储为重复的,并在日历上动态显示它们,但如果有人想更改事件的特定实例的细节,则必须将它们转换为正常事件。
我相信有更好的办法,但我还没找到。对重复发生的事件建模的最佳方法是什么?在这种方法中,您可以更改或删除特定事件实例的细节?
(我使用Ruby,但请不要让这限制了你的回答。如果有ruby特定的库或其他东西,那么最好知道。)
From these answers, I've sort of sifted out a solution. I really like the idea of the link concept. Recurring events could be a linked list, with the tail knowing its recurrence rule. Changing one event would then be easy, because the links stay in place, and deleting an event is easy as well - you just unlink an event, delete it, and re-link the event before and after it. You still have to query recurring events every time someone looks at a new time period never been looked at before on the calendar, but otherwise this is pretty clean.
Keep track of a recurrence rule (probably based on iCalendar, per @Kris K.). This will include a pattern and a range (Every third Tuesday, for 10 occurrences).
For when you want to edit/delete a specific occurrence, keep track of exception dates for the above recurrence rule (dates where the event doesn't occur as the rule specifies).
If you deleted, that's all you need, if you edited, create another event, and give it a parent ID set to the main event. You can choose whether to include all of the main event's information in this record, or if it only holds the changes and inherits everything that doesn't change.
请注意,如果允许不终止的递归规则,则必须考虑如何显示现在无限多的信息。
希望有帮助!
在javascript中:
处理重复的日程安排:
http://bunkat.github.io/later/
处理这些计划之间的复杂事件和依赖关系:
http://bunkat.github.io/schedule/
基本上,您创建规则,然后要求库计算接下来的N个重复事件(是否指定日期范围)。可以对规则进行解析/序列化,以便将它们保存到模型中。
如果您有一个重复发生的事件,并且只想修改其中一个重复发生的事件,您可以使用except()函数来取消特定的一天,然后为该条目添加一个新的修改过的事件。
库支持非常复杂的模式,时区,甚至croning事件。