0

I have two NSDate objects. One (call it date1) has timestamp in the future i.e 2012-07-16 12:00 and also this date is repeating daily. The other one (date2) has a timestamp also in the future i.e 2012-07-17 12:00.

Now I want to check if possibly date1 will clash with date2. Obviously it will not clash at 2012-07-16 12:00 but the day after (since it's repeating daily) it will clash with date2.

How could I implement this check?

Peter Warbo
  • 11,136
  • 14
  • 98
  • 193

1 Answers1

1

First check if the events would overlap on any date, i.e. using only the starting time and length of the events. If they do, then check if the dates are the same, or if the earlier of the dates is for an event that repeats enough times to occur on the date of the second event.

To compare the times you can use something like this to extract the hours and minutes from the NSDates: How do I get hour and minutes from NSDate?

For the second check you can first use NSDate's compare, followed by a timeIntervalSinceDate which you feed into something like this: How do I break down an NSTimeInterval into year, months, days, hours, minutes and seconds on iPhone? to get the number of days between the two dates, which you then can compare against the repeat count of the event.

Community
  • 1
  • 1
Michael
  • 57,169
  • 9
  • 80
  • 125