How to insert forever repeated events in sqlite3 iphone database? - iphone

I have one iphone application in which recurring events happens.the duration are like every day,every 2nd day,every 3rd day..,every week on mon,every week on tues,...,every second week on mon,..,every month on 1sr,every month on 2nd...,every second month on 1st,every second month on 2nd,... For some events there is end date but some events occurs forever.so how can i insert them automatically in sqlite3 database.eg.If an event repeats every 3rd day.how can i store it automatically after 3 days.or should i store all the events at the time of creation.If i store all the evnets at time of creation then the events that repeats forever.upto what duration i should store the value of them in database.
For this i have thought 2 approaches.one is storing just one occurance with repeated duration like every day.but in my application edit and delete functionality is also there.suppose event has one field event description then it can be different for different dates if user edit the events.events are displayed datewise on screen for a particular month and user can navigate to any previous and next month for current ,next and previous years.So if i use only single occurance then where should those edited or deleted events should be stored.
And if i take second approach store each occurance in database.Then upto what duration i should store the events which has no enddate.or is there a way that insert is automatically performed after specified duration.

Two ways, one an easy hack, one more difficult but correct :)
(1) Store each individual event for the next 10 years or so (or however long you want to!)
Good :
Easy and quick to implement
Bad :
Your db will get big very quickly.
What if the user wants to edit the details - how do you edit all of them at once?
What if the user wants to cancel / move the event- you have to delete all of them!
(2) Store some sort of 'event recurrence' information in the database with each event i.e. 'Every tuesday'
Good :
Only one event in the database, regardless of how many times it repeats.
Easy for the user to edit / delete the event - there's only one row in the database.
Bad:
More complicated event object - each event must have a list of 'when this event happens' information.
Makes very complicated event timings hard - i.e. 'last friday of every month'
Takes longer to implement
EDIT : My personal choice
I would choose option (2) - it takes longer to implement but I think option (1) will et you into trouble in the future.
I would have a data model like
Event has many Occurances
where your Event is the thing that the user has created with a description, start date etc and an Occurance is some sort of object that will say 'every friday' or 'not on the 4th'.
As part of creating an event, the user will say 'occurs once on Friday 13th' or 'occurs every Wednesday'. That information is used to create an array of Occurance objects.
Occurance would be a protocol that simply has the method occursOn: so you can have lots of different types of occurance (and you can add new types as your app gets more complicated).
The Event object would have a method something like occursOn: where you give it an NSDate and it returns if it occurs on that day. It does this by asking each of it's occurances in turn to see if they apply to that day.
To deal with deleted events, just add an Occurance to the end of the Event's array that overrides the others - i.e. 'not on Friday 13th'.
For example :
(1)
A user creates an event called 'My Event' starting on 1st Jan, occurring every Friday.
Your app would store
Event
description : 'My Event',
start date : 1st Jan 2011
occurances :
WeeklyOccurance
day : Friday
where WeeklyOccurance implements the <Occurance> protocol
(2)
The user asks to show the week's events, starting on Sunday the 8th Jan 2011
The app would :
For each day in the week
For each event in the database
if occursOn: this day
show the event on the ui
and for our event 'My Event', it would implement occursOn: like
- (BOOL)occursOn:(NSDate *)date
is this date before this event starts
if it is, return NO
set remembered = NO
for each occurance
does this occurance say 'yes','no' or '?' for this date?
if 'yes' set remembered YES
if 'no' return NO
if '?' continue the loop
return remembered
Because WeeklyOccurace only knows that it occurs on Fridays, it would return 'yes' for Fridays and '?' for all other days so the ui would show 'My Event' on Friday and not on any other days.
To add different types of occurance, just implement the <Occurance> protocol in different ways.
(3)
The user says actually it should be on every Friday apart from the 22nd
The app would create another Occurance, this time a NotOnThisDayOccurance and add it to the end of the Event's array i.e.
Event
description : 'My Event',
start date : 1st Jan 2011
occurances :
WeeklyOccurance
day : Friday
NotOnThisDayOccurance
day: 22nd Jan 2011
Now, if the users asks to display the weekly events, 'My Event' would look do this :
Ask the WeeklyOccurance if it's valid for friday the 22nd - this would return yes.
Ask the NotOnThisDayOccurance if it's valid for friday the 22nd - this would override the previous result and say NO
Therefore, the event would not show up on the 22nd but would show up on all the other fridays.

Related

How do I set the date to always read last Saturday in Tableau?

I do weekly reporting in Tableau and each page is labelled to say data is pulled through every Saturday (Image below).
My question is if there is a way to program that date to update every week on its own, without having to manually do it for every page on a 52 page report?
I'm not looking to update any data fields, just that label for each page.
See the below link on how you can pull in the last data refresh date:
http://kb.tableau.com/articles/howto/adding-data-refresh-time-stamp-to-view
Or you could have one calculated field that hold this date and add it to every page/view. Then you just have to update one field which will update every view.

How can I exclude DTSTART from generated events if its day not among days specified by BYDAY?

I'm using google-rfc-2445 to generate repeating events according to according to rfc-2445:
The "DTSTART" property for a "VEVENT" specifies the inclusive start of
the event. For recurring events, it also specifies the very first
instance in the recurrence set.
So, for example RRULE for event which occures every Friday 5 times:
DTSTART;TZID=US-Eastern:20160204T090000
RRULE:FREQ=WEEKLY;COUNT=5;BYDAY=FR;INTERVAL=1;
So according to rfc-2445 it will generate 6 events. First event on Thursday 4 February 2016, second event on Friday 5 February 2016, and so on.
How can I achieve that it will exclude first event if it isn't in a pattern? In the example above it should exclude first occurrence, 4 February 2016. In case of defining DTSTART;TZID=US-Eastern:20160205T090000 which is Friday it should leave first occurrence.
Can it be done by defining such "exclusion rule" in RRULE itself or I need to make a check in a code and if DTSTART isn't the same day as defined in BYDAY I should look for closest date in code (manually) and change DTSTART accordingly?
UPDATE
Ok, according to rfc-2445 and this question on google group: https://groups.google.com/forum/#!topic/google-rfc-2445/xqYFe411ysA
The "EXDATE" property can be used to exclude the value specified in
"DTSTART". However, in such cases the original "DTSTART" date MUST
still be maintained by the calendaring and scheduling system because
the original "DTSTART" value has inherent usage dependencies by other
properties such as the "RECURRENCE-ID".
it looks that I need to use EXDATE property to achieve what do I need. Trying to achieve this by following RRULE:
EXDATE;TZID=Asia/Jerusalem:20160210T000000
RRULE:FREQ=WEEKLY;COUNT=5;BYDAY=WE;INTERVAL=1;
And start date is: 2016-02-10T00:00:00.000+02:00 in the following code:
DateTimeIterable dti = DateTimeIteratorFactory.createDateTimeIterable(RRULE, DTSTART, dateTimeZone, true);
But it returns only 4 events, so it always remove first event.
From the description of the problem you give, you will get 6 events when DTSTART is added and you would not want it to be part of the list of instances and 5 events when it is a good date.
So what you want is to only get the last 5 events, which is possible by using the BYSETPOS in your RRULE, the following should do the trick:
BYSETPOS=-5,-4,-3,-2,-1
which will return in all cases the last 5 events that your RRULE gives regardless if the DTSTART is matching the pattern of your RRULE or not.

Display reoccurring events within date range

I am putting together a small call planner.
Calls are created and can be a once off event, or every week, month or yearly events beginning at a given time.
I can use generate_series to produce a list of dates, and this can JOIN the call_schedule table, but it is only including them for the date they begin.
I need the dates to show a list of dates selected with generate_series.
Eg: if it was every Monday at 9:30am there would be an entry for every Monday at 09:30:00 in the list of dates.
Dates without any calls would simply be empty, showing only the dates.
I have made a few attempts, and have put together sample data.
Any progress on this greatly appreciated.
http://derp.co.uk/559b1
Thanks
Kev

MongoDB Is there a way to find a dataset multiple times based on their child values

I am developing a social calendar application and want to make a feature for recuring events. I decided to use the following schhema as this might be the least memory intense for transfering (using meteorJS)
{
title: "Some Title",
/* ... some other fields for the event, e.g. location, name of venue, decription etc, a lot of data */
date: new Date(), // JS Date the event takes place first time or date for single event
repeatMethod: { //Every 2nd Monday in month, is used for generating repeatingEvents array
type: "monthly"
day: "Monday"
value: "2"
},
repeatingEvents: [
{
date: /*date for the first month */,
additionalStuff....
},
{
date: /* date for the second month */,
},
{
date: /*Date for the third month */,
canceled: true
}
]
}
I have several of these events (Around 100 Recuring events that repeat every week and around 50 events that repeat every month) and some single events that have no recurence.
Problem: I need to be able to list all events in a list like this:
Event 1 Occurence 1
Event 2 Occurence 1
Event 3 Single Event
Event 1 Occurence 2
Event 2 Occurence 2
Event 3 Occurence 1
...
but I want also to be able to limit the start and enddate of this list.
My first approach was to use single datasets per event but that blows up the database extremely. It also would be needed to store a complete event just for marking it canceled.
What way can I effectively find all events in a special timespan and list them ordered by date?
You're worrying about space when you should be worrying about seek times & user experience. Space is cheap, computations (and definitely user retention) aren't.
I suggest 2 collections, Events, Occurrences.
Store the eventId on the Occurrence document & index it.
So an event doc has _id, venue, title, etc.
An occurrence doc has _id, eventId, datetime, venue, title, etc.
Note:
Occurrence repeats venue because what happens if the regular venue isn't available a particular week? As a user, if changing the venue for 1 week changes the venue for all weeks, I'm gonna be grumpy.
We also repeat title (and all other fields, except the repetition info) so we don't need to access 2 collections for our queries. Denormalization is healthy, especially in a NoSQL environment.
This enables the user to change a field (like title) for a particular week (occurrence). If they want to change that field for ALL upcoming weeks, or maybe change the repeat structure, then they edit the event itself & that change to the event doc is propagated to all future occurrences.
A side effect of this structure is a really easy query for what you want: Occurrences.find({eventId: event, datetime: {$gt: date, $lt: date}).

iPhone - sorting a list of recurrent events

I have this list of recurrent events on a table at my app. Something like iCal. The user can set up events like:
meeting next tuesday 3 pm
meet wife every wednesday 6 pm
take pills every day 1 pm
take children saturday and sunday 9 am
The question is: how do I sort this to discover which will be the next event?
I am not sure the best way to create the core data entities.
Should I create the days of weeks as a second managed object on core data and create a to-many relationship to the first managed object representing the events (so each event can have one or more days of week objects). Should I create one managed object with boolean entities representing the days of week?
I can imagine different ways of doing this on core data, but I am not seeing how one can extract from core data a list sorted by event, I mean, a list that shows first the events close to today's date and last the event more distant.
What I ask here is not code, but rather, ideas on how this should be constructed... what do you guys suggest as the best way to put this together.
thanks.
What I would do is have your "Event" entity in Core Data have a date and a recurrence attribute to it. Set the date to when the event occurs and recurrence to how many seconds until the next time it occurs. When the event happens, update the date with -dateByAddingTimeInterval with the current date and the recurrence interval.
You can then sort by date to get your next event. If you want to show the event multiple times, like for a month calendar layout, loop on -dateByAddingTimeInterval: with the recurrence interval and mark it on your view during each iteration.