I need to build an application which has some sort of a calendar and reminder functionalities (i.e. remind me seven and three days before an event takes place). events can be recurring (i.e. birtday -> yearly, pay the rent -> monthly and so on).
Im looking for a smart way to store these event dates (and notification "actions") in the DB. My problem lies in the "recurring" feature. How do i store an event taking place once a week ? I can not make 52 entries in the DB per year. Or can i ? But also i can not only store the first event and then make some calculations in the DB. O can i ?
any ideas ? and pointers ? any recomended pattern ?
Why would you need to do the calculations in the DB if you only store the start date?
Why are you using a DB at all?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
You might look into using CRON or Quartz (which also uses these expressions) so you don't have to write this beast. [ February 22, 2007: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jun 19, 2001
Ilja: The application has one part which is some sort of Calendar app -> user can enter events (i.e. Birthday of my Grandmother at 28. March 1933) and register reminders (send me an email two weeks before the event starts and a Textmessage 6 hours before the event starts). Also the user should be able to get a view of events in the future. So thats why i want to store the events and the reminder actions in the DB.
Since my Grandmothers celebrates here Birthday once a year i need the reminders every year (recurrent events). And thats where im not clear how to do this.
I could add only the first ocurrence of the event (date of birth) and the reccurent mode (No recurrence, yearly, monthly, ...) or i could store 120 entries (1933 - 2053). But how do i know how far in the future i should add the events ? what if the event is daily ? do i add 365 entries per year ?
Stan: Thanks for the hint. I'll look into quartz. But to send notifications i would need to load all the events and parse the CRON string and see if i would need to fire a reminder action ? I need to think this trough :-)
Thanks for your help!
Joined: Jan 29, 2003
I did a similar scheduler in a previous life. I stored an expression for how often something should repeat and the next scheduled event. When that time came along, I fired the event, calculated a new next from the expression and stored the new next. I only had to evaluate the expression and compute a new time after something fires.
You'll need to figure out your own rules for what happens if you miss the event time - say you start the program and find an event that should have fired yesterday or maybe the last three days. You'd also have options to compute the next from when the current one was scheduled to begin, really began or when it ended. For this kind of calendaring, is the scheduled start your best choice?
Offloading the whole job to CRON or Quartz - not just borrowing their expression syntax - might be a cost effective alternative to writing a tricky little subsystem. Code not written usually has very few bugs. [ February 26, 2007: Message edited by: Stan James ]
Joined: Jun 19, 2001
Code not written usually has very few bugs.
Code i write does not have bugs :-)
I was thinking along the "store expression and the next event in cleartext" too. I think this is the way to go or at least to thing to start with.
Thanks for your hints.
Joined: Jul 11, 2001
Originally posted by pascal betz: Ilja: The application has one part which is some sort of Calendar app -> user can enter events (i.e. Birthday of my Grandmother at 28. March 1933) and register reminders (send me an email two weeks before the event starts and a Textmessage 6 hours before the event starts). Also the user should be able to get a view of events in the future. So thats why i want to store the events and the reminder actions in the DB.
That explains why you want to store recurring events somehow.
It doesn't exactly explain why you want to store them in a DB, though I'm ok with simply take it as a given.
It doesn't explain at all why, when you stored the start date and the interval in the DB, you needed to do any calculations in the DB. If you could elaborate on your thinkings here...