Last active
December 26, 2015 18:19
-
-
Save advantis/7193036 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// Copyright © 2013 Yuri Kotov | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSCalendar (ADVCalculations) | |
- (NSComparisonResult) compareDate:(NSDate *)date1 toDate:(NSDate *)date2 withGranularity:(NSCalendarUnit)granularity; | |
- (BOOL) isDate:(NSDate *)date1 equalToDate:(NSDate *)date2 withGranularity:(NSCalendarUnit)granularity; | |
@end |
This file contains 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
// | |
// Copyright © 2013 Yuri Kotov | |
// | |
#import "NSCalendar+ADVCalculations.h" | |
@implementation NSCalendar (ADVCalculations) | |
- (NSComparisonResult) compareDate:(NSDate *)date1 toDate:(NSDate *)date2 withGranularity:(NSCalendarUnit)granularity | |
{ | |
NSCalendarUnit unitFlags = granularity * 2 - 2; | |
date1 = [self dateFromComponents:[self components:unitFlags fromDate:date1]]; | |
date2 = [self dateFromComponents:[self components:unitFlags fromDate:date2]]; | |
return [date1 compare:date2]; | |
} | |
- (BOOL)isDate:(NSDate *)date1 equalToDate:(NSDate *)date2 withGranularity:(NSCalendarUnit)granularity | |
{ | |
return NSOrderedSame == [self compareDate:date1 toDate:date2 withGranularity:granularity]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment