Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stadidas

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
Hi everyone,

I have been having a play around recently with an app I've been writing, and I want to implement a feature that needs repeating dates. By this I mean you can set a date and an interval, and at those intervals an event happens. And example of what I mean is in the application Cha-Ching:

dates.png


I have looked at the documentation for NSCalendarDate and NSCalendar, but can't see an easy way of achieving this. All I can think of is to have an object which stores an initial date, an interval value, and the date when an event was last raised. NSCalendarDate's years:months:days:hours:minutes:seconds:sinceDate: method could be used with todays date to see if the last time an event was raised falls inside or outside the specified time interval. If today is outside the interval, then an event can be triggered.
This seems like a pretty long winded solution; does anyone have any pointers that may help?
 

MacDonaldsd

macrumors 65816
Sep 8, 2005
1,005
0
London , UK
Hi,

Im not exactly sure what you are trying to achieve, but if your are creating an event and then setting it to repeat, you could do this using the method below.


Code:
- (NSCalendarDate *)dateByAddingYears:(NSInteger)year months:(NSInteger)month days:(NSInteger)day hours:(NSInteger)hour minutes:(NSInteger)minute seconds:(NSInteger)second

NSCalendarDate *now = [NSCalendarDate calendarDate];
NSCalendarDate *nextWeek = [now dateByAddingYears:0 months:0
    days:7 hours:0 minutes:0 seconds:0];

The major problem with this method is that it doesn't create any relationship between events, i.e. if you change the first event it wont alter the subsequent events.
 

stadidas

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
Thanks for the help. I guess I was being a bit vague, as that's not quite what I meant.
Basically, I want to create a way of managing recurring payments (very much like Cha-ching). The idea being that you can set a start date, and then set a repeat interval (say, every month), and then every month after the start date a reminder will be displayed to the user.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.