-(void)deleteElementFromCalendarDB {
CFGregorianDate gregorianStartDate, gregorianEndDate;
CFGregorianUnits startUnits = {-2, 0, 0, 0, 0, 0};
CFGregorianUnits endUnits = {1, 0, 0, 0, 0, 0};
CFTimeZoneRef timeZone = CFTimeZoneCopySystem();
gregorianStartDate = CFAbsoluteTimeGetGregorianDate(
CFAbsoluteTimeAddGregorianUnits(CFAbsoluteTimeGetCurrent(),
timeZone,startUnits),timeZone);
gregorianStartDate.hour = 0;
gregorianStartDate.minute = 0;
gregorianStartDate.second = 0;
gregorianEndDate = CFAbsoluteTimeGetGregorianDate(
CFAbsoluteTimeAddGregorianUnits(CFAbsoluteTimeGetCurrent(),
timeZone, endUnits),timeZone);
gregorianEndDate.hour = 0;
gregorianEndDate.minute = 0;
gregorianEndDate.second = 0;
NSDate* startDate = [NSDate dateWithTimeIntervalSinceReferenceDate:
CFGregorianDateGetAbsoluteTime(gregorianStartDate, timeZone)];
NSDate* endDate = [NSDate dateWithTimeIntervalSinceReferenceDate:
CFGregorianDateGetAbsoluteTime(gregorianEndDate, timeZone)];
CFRelease(timeZone);
NSError *err;
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate
endDate:endDate
calendars:nil];
NSArray *eventListS = [self.eventStore eventsMatchingPredicate:predicate];
for (EKEvent *event in eventListS) {
[self.eventStore removeEvent:event span:EKSpanFutureEvents error:&err];
}
if (err == noErr) {
UIAlertView *alert =[[UIAlertView alloc]itWithTitle:@"All Events were deleted" message:@"How about that?"
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}