What's the best way to model recurring events in a calendar application?

后端 未结 18 2472
感情败类
感情败类 2020-11-27 08:54

I\'m building a group calendar application that needs to support recurring events, but all the solutions I\'ve come up with to handle these events seem like a hack. I can li

18条回答
  •  [愿得一人]
    2020-11-27 09:17

    There can be many problems with recurring events, let me highlight a few that I know of.

    Solution 1 - no instances

    Store original appointment + recurrence data, do not store all the instances.

    Problems:

    • You'll have to calculate all the instances in a date window when you need them, costly
    • Unable to handle exceptions (ie. you delete one of the instances, or move it, or rather, you can't do this with this solution)

    Solution 2 - store instances

    Store everything from 1, but also all the instances, linked back to the original appointment.

    Problems:

    • Takes a lot of space (but space is cheap, so minor)
    • Exceptions must be handled gracefully, especially if you go back and edit the original appointment after making an exception. For instance, if you move the third instance one day forward, what if you go back and edit the time of the original appointment, re-insert another on the original day and leave the moved one? Unlink the moved one? Try to change the moved one appropriately?

    Of course, if you're not going to do exceptions, then either solution should be fine, and you basically choose from a time/space trade off scenario.

提交回复
热议问题