Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'd like to hear some ideas how to sync calendar events. Say I have two calendars having fields (id, title, start, end, updated, location and description). I'm struggling with starting point. Its easy if all events are new and not overlapping with each other. But say I already have events on calendars, some are supposedly same events, some are separate events, some maybe same events, but their attributes have changed, like location, title, start and end time. How would you actually make sync between calendars with reasonable smart functionality?

share|improve this question
    
I think the general question you are looking at here is how to identify duplicate records in the two datasets. There are several commercial applications available that do this kind of thing for Outlook. A quick Google search produced Duplicate Killer. I don't know this particular one, but you can probably learn a lot or at least get some inspiration by reading their documentation or playing around with the trial version to see what kind of criteria they use. –  PersonalNexus Jan 8 '12 at 18:41
    
Thats true, I was already going to find array intersect and combine functions to do the job, but thought its good to hear some opinions first. I'm doing this between Google calendar and Facebook events, lets see if Duplicate Killer gives killer ideas... They say: "Compare events by location, start time,subject, etc. to search for duplicate events manually." so we are on right track I guess. –  PHPGAE Jan 8 '12 at 19:00
add comment

2 Answers

up vote 4 down vote accepted

For each event, besides its "event time" you also need to keep track of one more time attribute, the time of last modification. This takes care of the simple and, ehm, lets say, uneventful sync scenario: events that have been modified since the last sync time get copied over.

The problems start if there is a possibility that two events may have both been modified since the last sync, and you don't want changed attributes from one overwriting changed attributes in the other. We call this situation a "conflict". In order to overcome conflicts, you could keep track of the time of last modification of each attribute within an event, but this would a) complicate things a lot, and b) it would only fix conflicts in the cases when dissimilar attributes have been changed. You would still have a problem when the same attribute has been changed. So, a better approach for handling conflicts is to always present the user with the two records side by side, highlight for them the changed attributes, and let them decide which changed attribute of the left record overwrites the corresponding attribute on the right record, and vice versa.

The case of overlapping events can also be seen as a conflict, which though needs to be handled specially: either the duration of one event (the one occurring earlier in time) will need to be shortened, or the starting time of the other event (the one occurring later in time) will have to be moved forward, possibly also adjusting its duration.

share|improve this answer
    
Great thoughts! I assumed this can end up pretty complicated, so compromise I need. Actions like: add, update and delete will require some sort of datastore. Naturally I can't add fields on calendars themselves, so if I want to track changes I need to store events on third "calendar". On add operation would you just check overlapping time to find conflict? If time is same, but location is different it could mean two possibilities: new event or old one was updated. On delete there wouldn't be counterpart for the event, but datastore will tell there used to be -> delete event on sync process. –  PHPGAE Jan 8 '12 at 18:55
1  
Yes, on add of course you need to check for overlaps. ((TimeA >= TimeB AND TimeA < TimeB + DurB) OR (TimeA <= TimeB AND TimeA + DurA > TimeB)) –  Mike Nakis Jan 8 '12 at 19:06
add comment

if every event has a unique "eventID" and a datetime field for "lastmodified" the case is easy. (i use these for ical events in mozilla-calendar and msoutlook 2010). since my motorola handset calender does not have the eventid i have a copy of the events on the pc that includes the eventid.

you also need this local copy if you want to handle "deleted events" because else deletions will reapear after syncing.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.