Created
October 23, 2014 13:01
-
-
Save vikingosegundo/2c5bf0340199069de49b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
NSArray *dates = @[ | |
[[NSCalendar currentCalendar] dateFromComponents:({ | |
NSDateComponents *c = [[NSDateComponents alloc] init]; | |
c.year = 2010; | |
c.month = 12; | |
c.day = 9; | |
c.hour = 12; | |
c.minute = 30; | |
c; | |
})], | |
[[NSCalendar currentCalendar] dateFromComponents:({ | |
NSDateComponents *c = [[NSDateComponents alloc] init]; | |
c.year = 2014; | |
c.month = 10; | |
c.day = 23; | |
c.hour = 12; | |
c.minute = 30; | |
c; | |
})], | |
[[NSCalendar currentCalendar] dateFromComponents:({ | |
NSDateComponents *c = [[NSDateComponents alloc] init]; | |
c.year = 2014; | |
c.month = 10; | |
c.day = 23; | |
c.hour = 1; | |
c.minute = 30; | |
c; | |
})], | |
[[NSCalendar currentCalendar] dateFromComponents:({ | |
NSDateComponents *c = [[NSDateComponents alloc] init]; | |
c.year = 2014; | |
c.month = 10; | |
c.day = 30; | |
c.hour = 12; | |
c.minute = 30; | |
c; | |
})], | |
[[NSCalendar currentCalendar] dateFromComponents:({ | |
NSDateComponents *c = [[NSDateComponents alloc] init]; | |
c.year = 2014; | |
c.month = 10; | |
c.day = 24; | |
c.hour = 12; | |
c.minute = 30; | |
c; | |
})], | |
[[NSCalendar currentCalendar] dateFromComponents:({ | |
NSDateComponents *c = [[NSDateComponents alloc] init]; | |
c.year = 2014; | |
c.month = 10; | |
c.day = 24; | |
c.hour = 5; | |
c.minute = 0; | |
c; | |
})], | |
]; | |
NSDate *now = [NSDate date]; | |
NSDate *mondayThisWeek; | |
NSDate *mondayNextWeek; | |
NSTimeInterval lengthOfWeek; | |
[[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay startDate:&mondayThisWeek interval:&lengthOfWeek forDate:now]; | |
mondayNextWeek = [mondayThisWeek dateByAddingTimeInterval:lengthOfWeek]; | |
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF >= %@) AND (SELF < %@)", mondayThisWeek, mondayNextWeek]; | |
NSArray *filteredDates = [dates filteredArrayUsingPredicate:predicate]; | |
NSIndexSet *dateIndicies = [filteredDates indexesOfObjectsPassingTest:^BOOL(NSDate *date, NSUInteger idx, BOOL *stop) { | |
NSDate *rangeStart; | |
NSDate *rangeEnd; | |
NSTimeInterval lenghtOfDay; | |
[[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay startDate:&rangeStart interval:&lenghtOfDay forDate:now]; | |
rangeEnd = [[NSCalendar currentCalendar] dateByAddingComponents:({ | |
NSDateComponents *c = [[NSDateComponents alloc] init]; | |
c.hour = 20; | |
c.minute = 0; | |
c; | |
}) toDate:rangeStart options:0]; | |
rangeStart = [[NSCalendar currentCalendar] dateByAddingComponents:({ | |
NSDateComponents *c = [[NSDateComponents alloc] init]; | |
c.hour = 7; | |
c.minute = 30; | |
c; | |
}) toDate:rangeStart options:0]; | |
return ([rangeStart timeIntervalSince1970] < [date timeIntervalSince1970] && [date timeIntervalSince1970] < [rangeEnd timeIntervalSince1970]); | |
}]; | |
filteredDates = [filteredDates objectsAtIndexes:dateIndicies]; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment