title: local notification of events that already happened in the past
body: <p>I am making a reminder app, where user create some event with date and time and choose when he should get noticed about it by choosing a fire date (interval before this event: right now, 5, 15, 30 minutes ago, and so on) and repeat interval (never, daily, weekly, monthly and every year). The problem is: when user creates an event, that already happens, for example event should occur in 10 april, and today is 16 april, he should be reminded about this event right in time, but user gets notification about this event right after creating it. So it shouldn't happened. How can I avoid this?
  Here is the method, that creates notification</p>
  
  <pre><code>- (void)notificationWithNote:(Note *)scheduledNote deleteThisNotification:(BOOL)deleteNotification {
  
      NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
      unsigned int unitFlags = NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit;
      NSDateComponents *comp = [calendar components:unitFlags fromDate:scheduledNote.date];
  
          ToDoItem *todoitem = [[ToDoItem alloc] init];
          todoitem.day = [comp day];
          todoitem.month = [comp month];
          todoitem.year = [comp year];
          todoitem.hour = [comp hour];
          todoitem.minute = [comp minute];
          todoitem.eventName = scheduledNote.event;
  
      NSDateComponents *dateComps = [[NSDateComponents alloc] init];
      [dateComps setDay:todoitem.day];
      [dateComps setMonth:todoitem.month];
      [dateComps setYear:todoitem.year];
      [dateComps setHour:todoitem.hour];
      [dateComps setMinute:todoitem.minute];
      NSDate *itemDate = [calendar dateFromComponents:dateComps];
      [dateComps release];
  
  
      UILocalNotification *localNotif = [[UILocalNotification alloc] init];
      if (localNotif == nil)
          return;
      if ([scheduledNote.remindTime intValue] == 1)
          localNotif.fireDate = itemDate;
      else
          localNotif.fireDate = [itemDate dateByAddingTimeInterval:-([scheduledNote.remindTime intValue]*60)];
  
  
      switch ([scheduledNote.repeatOption intValue]) {
          case 0:
              localNotif.repeatInterval = 0;
              break;
          case 1:
              localNotif.repeatInterval = NSDayCalendarUnit;
              break;
          case 2:
              localNotif.repeatInterval = NSWeekCalendarUnit;
              break;
          case 3:
              localNotif.repeatInterval = NSMonthCalendarUnit;
              break;
          case 4:
              localNotif.repeatInterval = NSYearCalendarUnit;
              break;
          default:
              break;
      }
  
      localNotif.timeZone = [NSTimeZone defaultTimeZone];
      localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"%@ begins", nil), scheduledNote.event];
      localNotif.alertAction = NSLocalizedString(@"View Details", nil);
      localNotif.soundName = UILocalNotificationDefaultSoundName;
      localNotif.applicationIconBadgeNumber = 1;
      NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:todoitem.eventName,ToDoItemKey, @"Timenote is coming", MessageTitleKey, nil];
      localNotif.userInfo = infoDict;
  
      if (deleteNotification)
          [[UIApplication sharedApplication] cancelLocalNotification:localNotif];
      else
          [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
  
      NSLog(@"fire date: %@",[localNotif.fireDate description]);
      [todoitem release];
      [localNotif release];
  }
  </code></pre>
  
  <p>This bug happens only if user doesn't choose any repeat interval. If event repeats every day/week/month/year, remind appears right in time. So the problem is actual if <code>localNotif.repeatInterval == 0</code> </p>