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

后端 未结 18 2547
感情败类
感情败类 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:24

    I have developed multiple calendar-based applications, and also authored a set of reusable JavaScript calendar components that support recurrence. I wrote up an overview of how to design for recurrence that might be helpful to someone. While there are a few bits that are specific to the library I wrote, the vast majority of the advice offered is general to any calendar implementation.

    Some of the key points:

    • Store recurrence using the iCal RRULE format -- that's one wheel you really don't want to reinvent
    • Do NOT store individual recurring event instances as rows in your database! Always store a recurrence pattern.
    • There are many ways to design your event/exception schema, but a basic starting point example is provided
    • All date/time values should be stored in UTC and converted to local for display
    • The end date stored for a recurring event should always be the end date of the recurrence range (or your platform's "max date" if recurring "forever") and the event duration should be stored separately. This is to ensure a sane way of querying for events later.
    • Some discussion around generating event instances and recurrence editing strategies is included

    It's a really complicated topic with many, many valid approaches to implementing it. I will say that I've actually implemented recurrence several times successfully, and I would be wary of taking advice on this subject from anyone who hasn't actually done it.

提交回复
热议问题