PDA

View Full Version : Repeating Dates in Cocoa




stadidas
Feb 2, 2008, 02:39 PM
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:

http://www.matefeedkillrepeat.com/images/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
Feb 2, 2008, 03:05 PM
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.


- (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
Feb 2, 2008, 04:37 PM
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.