How to create recurring calendar events?
Asked Answered
B

3

9

I am using asp mvc 3, jquery full calendar, ms sql sever 2008 and c#.

I am wondering if anyone knows how to make recurring events?

I am unsure how to make them.

For instance in google calendar you can make an appointment repeat yearly forever. I doubt that they generate that appointment X times in the database.

I am wondering how I could have one row in my db and somehow know to call that up when needed.

Also google calendar and outlook have lots of repeating options like repeat on the 1st month, last month and etc.

Is there any libraries build that have this? Or do I got to make it from scratch?

P.S

I am on a shared host so a solution has to work with limited rights.

Bonds answered 9/2, 2011 at 19:32 Comment(2)
This question might be helpful: #1274503Toulon
Have you implemented this? I also need of sameFerruginous
C
9

Generating all possible repetitions of an event would (in theory) fill up your storage with events that would most likely never ever be seen by the user (congrats on your 999,999,999,999,999,999,999th birthday!).

It takes a bit more work, but the solution is to basically store a table (or tables) of repetition rules which you link your calendar entries to as you build a calendar:

"for every day of the week being shown, check for events which repeat on those days" "for every week of the month being shown, check for events which repeat in those weeks" "for every month in a year", etc...

How many of these checks you have to do depends on how many types (and duration) of repetitions you'd want.

As for supressing events, that's yet another table listing points at dates/times which have to be supressed. "if showing mondays, show all events that repeat on months, except the ones listed in the supression table"

comment followup:

Well, you'd have your standard calendar entry table, to store the core information. date/time, etc... Then at least two other tables to store the repeat information. One that stores your repetition rules. "every monday", "first day of month", "every year", etc..., and a third table that links between the calendar entries and the the rules

so:

 calendar entries table  <--->  link table  <--->  repeat rules table

Querying would be a matter of building things so that for the date you're considering, the appropriate rules come out and give you the IDs of calendar entries to display. Could get ugly if you do a fancy query that dynamically links to the appropriate rules based on a date you've passed in.

Cockle answered 9/2, 2011 at 19:40 Comment(6)
@Marc B - Can you elaborate more? Like lets take repeats every monday. So how would building of the calendar look? Would I do a query to find all tasks that are "repeat on Monday" then built 4 for that entire week?Bonds
@Marc B - So this link table would just just have which id(ie which rule is being used). Then I would a query on this table and find out what rules are being used?Bonds
Basically yes. The rules link might have extra info, like "only for the next 10 mondays", or "stop repeating in 2011", etc... but basically - some calendar entries, and some extra data on how/when to repeat them.Cockle
Marc B - Ok I going have to think on how to do that. How about reminders. Would that have to link too?Bonds
Depends on the reminder. For simple ones, a single field in the main calendar entry table would do, with a time offset for when the reminder should show up, turning the reminder into kind of another type of schedule entryCockle
Marc B - Well right now how I have it. The value is the date the reminder should be sent off.Bonds
L
1

Since you've included the #google-calendar tag, I am guessing that's what you're working with. Google Calendar uses REST and JSON calls. Here's an example:

{
  "summary": "Daily project",
  "start": {
    "dateTime": "2011-12-12T10:00:00",
    "timeZone": "Europe/Zurich"
  },
  "end": {
    "dateTime": "2011-12-12T11:00:00",
    "timeZone": "Europe/Zurich"
  },
  "recurrence": [
    "RRULE:FREQ=DAILY;COUNT=5"
  ]
}

This will create an event titled "Daily project" that happens daily from 10 AM to 11 AM, and repeats it for 5 days in a row.

Since you're using C#, you can also use the Google API (v3) Event object. This has all of the properties that you need to create a recursive event. However, you should still have a look at the JSON structure to figure out how the recursion rules are formed.

If you're not using Google Calendar, you can still use their API as a guide: just create rules for repeated events rather than actual instances. Use a thread or timer to query the database every minute for new events, based on single events (which have no recursion rules) and repeated event rules.

Lemmy answered 12/2, 2015 at 16:22 Comment(0)
R
0

Whenever someone asks a question like this the link to book "Developing Time-Orientated Database Applications in SQL" comes up. It's available legitimately as a free PDF and on Amazon.

Remittance answered 9/2, 2011 at 20:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.