Esempio n. 1
0
/*
 * Do we need an alert? if so schedule one. 
 */
int determine_if_alarm_needed(int num) {
  // Copy the right event across
  memcpy(&event, &events[num], sizeof(Event));
	
  // Alarms set
  int alarms_set = 0;
	
  // Ignore all day events
	if (event.all_day) {
	  return alarms_set; 
	}

  // Is the event today
  if (is_date_today(event.start_date) == false) {
	  return alarms_set;
  }

  // Compute the event start time as a figure in ms
  int time_position = 9;
  if (event.start_date[5] != '/')
		time_position = 6;

  int hour = a_to_i(&event.start_date[time_position],2);
  int minute_position = time_position + 3;
  if (event.start_date[time_position + 1] == ':')
	  minute_position = time_position + 2;
  int minute = a_to_i(&event.start_date[minute_position],2);
	
  uint32_t event_in_ms = (hour * 3600 + minute * 60) * 1000;
	
  // Get now as ms
  time_t rawtime;
  time(&rawtime);
  struct tm *time = localtime(&rawtime);
  uint32_t now_in_ms = (time->tm_hour * 3600 + time->tm_min * 60 + time->tm_sec) * 1000;

  // Work out the alert interval  
  int32_t alert_event = event_in_ms - now_in_ms;

  // If this is negative then we are after the alert period
  if (alert_event >= 0) {

	  // Make sure we have the resources for another alert
	  alerts_issued++;
	  if (alerts_issued > MAX_ALLOWABLE_ALERTS)	
		  return alarms_set;

	  // Queue alert
	  queue_alert(num, event.title, alert_event);
	  alarms_set++;
  }

  return alarms_set;
}
Esempio n. 2
0
/*
 * Do we need an alert? if so schedule one. 
 */
int determine_if_alarm_needed(int num) {
  // Copy the event for easy access
  Event event;	
  memcpy(&event, &g_events[num], sizeof(Event));
	
  // Alarms set
  int alarms_set = 0;
	
  // Ignore all day events
	if (event.all_day) {
	  return alarms_set; 
	}

  // Is the event today
  if (is_date_today(event.start_date) == false) {
	  return alarms_set;
  }
 	
  // Does the event have an alarm
  if (event.alarms[0] == -1 && event.alarms[1] == -1) {
	  return alarms_set;
  }

  // Compute the event start time as a figure in ms
  int time_position = 9;
  if (event.start_date[5] != '/')
		time_position = 6;

  int hour = a_to_i(&event.start_date[time_position],2);
  int minute_position = time_position + 3;
  if (event.start_date[time_position + 1] == ':')
	  minute_position = time_position + 2;
  int minute = a_to_i(&event.start_date[minute_position],2);
	
  uint32_t event_in_ms = (hour * 3600 + minute * 60) * 1000;
	
  // Get now as ms
  PblTm time;
  get_time(&time);
  uint32_t now_in_ms = (time.tm_hour * 3600 + time.tm_min * 60 + time.tm_sec) * 1000;

  // First alart
  if (event.alarms[0] != -1) {
	  
  	// Work out the alert interval  
  	int32_t alert_event = event_in_ms - now_in_ms - (event.alarms[0] * 1000);

  	// If this is negative then we are after the alert period
  	if (alert_event >= 0) {
		
		// Make sure we have the resources for another alert
		g_alerts_issued++;
		if (g_alerts_issued > MAX_ALLOWABLE_ALERTS)	
			return alarms_set;
		
		// Queue alert
		queue_alert(num, event.alarms[0], event.title, alert_event, event.has_location ? event.location : "");
		alarms_set++;
    }
  }

  // Second alart
  if (event.alarms[1] != -1) {

    // Work out the alert interval  
  	int32_t alert_event = event_in_ms - now_in_ms - (event.alarms[1] * 1000);

  	// If this is negative then we are after the alert period
  	if (alert_event >= 0) {

		// Make sure we have the resources for another alert
		g_alerts_issued++;
		if (g_alerts_issued > MAX_ALLOWABLE_ALERTS)	
			return alarms_set;

		// Queue alert
		queue_alert(num + 15, event.alarms[1], event.title, alert_event, event.has_location ? event.location : "");
		alarms_set++;
    }
  }

  return alarms_set;
}