I have a date component say birthdayComponent (it has month and day in it) and I want to check if it lies between to other components.. say (beginDaYComponent and endDayComponent).
I want to check if my birthday component lies between these two dates..? How can I achieve this as I also have to consider the boundary cases say 29th Feb and I will have the endDayCompnents values as 3 for Month and 1 for Day. You can have a look at the code below for more info.
NSDateFormatter *dateFormat = [NSDateFormatter new];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSDateComponents *dayComponent = [[NSDateComponents alloc] init];
NSDateComponents *beginDayComponent = [[NSDateComponents alloc] init];
NSDateComponents *endDayComponent = [[NSDateComponents alloc] init];
NSCalendar *theCalendar = [NSCalendar currentCalendar];
NSMutableArray* birthdayFitlerArray = [NSMutableArray new];
for (NSString* dateString in birthdaysArray)
{
NSDate* birthdayDate = [dateFormat dateFromString:dateString];
dayComponent.day = -1;
NSDate* beginDate = [theCalendar dateByAddingComponents:dayComponent toDate:currentLeg.date options:0];
dayComponent.day = 1;
NSDate* endDate = [theCalendar dateByAddingComponents:dayComponent toDate:currentLeg.date options:0];
beginDayComponent = [theCalendar components:(NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:beginDate];
endDayComponent = [theCalendar components:(NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:endDate];
NSDateComponents* birthdayComponents = [theCalendar components:(NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:birthdayDate];
}
UPDATE:
I want to omit out the YEAR component for the date.