iPhone - sorting a list of recurrent events - iphone

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.

Related

How can I make a database structure in mongodb for saving the date range?

Here I'm saving the date range using golang. Suppose we have to save the all monday comes between the range of the 1-may-2018 to 14-july-2018.
How we will find all the monday between these range using golang and on the other hand we have set the start_time (8:00 A.M.) and the end_time (6:00 P.M.) of the first two coming monday in the database but on the third monday we have a change in the schedule that there is a time change like start_time (9:00 A.M.) and end_time (5:00 P.M.). Then how I will make my database to make this situation in practically using the golang.
Can Anybody help me for this to solve this solution. I made a database for and I do ppr work on it and make some fields shown below:-
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Start_hours (int)
Start_minutes (int)
End_hours (int)
End_minutes (int)
Start_date (timestamp)
End_date (timestamp)
How I will select monday between the selected range and how will I do the situation I explained above can anybody give guidance to me to make this situation easier. Thank you if this is a basic question then I'm really sorry.
I'd make something like this.
Find the first Monday date from the date range (see for example How do I get the first Monday of a given month in Go?
Mondays happen every week, so you can easily find the rest of dates by adding 7 days till the end date
Store all the Monday dates you found with the start and end times
I wouldn't bother with hours and minutes as you can easily get them from the timestamps in Go. Here is the simplified DB structure I would make
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Date (timestamp) // the actual date
Start (timestamp)
End (timestamp)
You don't need any more fields. You can get the day of the week (Day (string) in your structure, e.g. Monday) from the Date field too, but I believe if you want to query the collection by different days, this might speed things up, but be careful if you need to adjust for time zones. If you work with more than one, then store everything in UTC and you may have an extra filed Timezone, cos a date could be Monday for one zone and Sunday for another.
So, the Schedule will hold weekdays and start and end times for each of them. I'm not sure if you need to store initial date ranges, the Schedule collection will hold that range as well, form the first record to the last one. In my mind, I'd initially populate the collection with a given date range, then later on, I can modify it by adding new days, or deleting them.
When you query this collection with some start and end date range for the Date field, if your first result comes newer than 7 days from the start, this means you miss 1 or more entries from the start. If the last result comes older than 7 days from the range end, this means you miss some entries prior to the range end.
There is nothing specific to Go, in my opinion, Go works well with dates and you don't need any special date structures in your DB.

How to get only the first 6 months action of all my records

I'm pretty new in Tableau. I have looked at the forum already and the answered suggested. But I'm not quite sure it match my question.
I have a bunch of records. This is about registration for a sport lesson depending on time. All of them have a start date and and some of them a finish date. The other never finish (They continue until date T with T = now).
My goal is to compare only the first 6 months of all my records, I think there are 50 of them, like the evolution during this period of time. So, for some the start date would be in January 2009, for some other, it would be in May 2016, etc.
As field provided, I have the start date and the number of person that have subscribed those lesson through time.
So, do you if there is any to achieve this goal? Is there enough detail for you to understand what I am saying ?
Thx to you guys !!
EDIT
You can find enclosed a screenshot of the result that I already have.
number of registration for all lesson through time
I'm not sure to be clear, what I try to do is to compare the first 6 months only of each courses. So the evolution of the first 6 months of this course compare to the evolution of the first 6 months of this other course and so on :)
If I understand your question correctly you are wanting to show only the first six months of your data but you want this by each category.
I am assumuming that by definition this means 6 months from the first record in your data for each category.
In order to achieve this I would create a true/false flag using a level of detail expression. As you are new to tableau I would suggest you do some reading on this but basically you can force a calculation to be at a certain level of the data rather than at the row level. You use this to find the minimum date in the table and then use a date diff to return true if the actual date field is within 6 months of this.
Create a calculated field as follows:
[date] <= DATEADD('month', 6, { FIXED [category] :min([date])})
Then drag this onto your filters pane and select "TRUE". This should give you only the first six months of records for each category.
Let me know if you need anything else.

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

How to insert forever repeated events in sqlite3 iphone database?

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.