Skip to content

Commit

Permalink
Merge pull request MatthewYork#40 from Zhukn1/is_weekend
Browse files Browse the repository at this point in the history
Added method to determine if date is a weekend. (Uses current calendar).
  • Loading branch information
MatthewYork committed Jan 26, 2015
2 parents 9e55c35 + dcdddfd commit 63bd4d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions DateTools/NSDate+DateTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ NSLocalizedStringFromTableInBundle(key, @"DateTools", [NSBundle bundleWithPath:[
- (BOOL)isToday;
- (BOOL)isTomorrow;
-(BOOL)isYesterday;
- (BOOL)isWeekend;

#pragma mark - Date Components With Calendar

Expand Down
15 changes: 15 additions & 0 deletions DateTools/NSDate+DateTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,21 @@ -(BOOL)isYesterday{
return [tomorrow isEqualToDate:otherDate];
}

- (BOOL)isWeekend {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSRange weekdayRange = [calendar maximumRangeOfUnit:NSCalendarUnitWeekday];
NSDateComponents *components = [calendar components:NSCalendarUnitWeekday
fromDate:self];
NSUInteger weekdayOfSomeDate = [components weekday];

BOOL result = NO;

if (weekdayOfSomeDate == weekdayRange.location || weekdayOfSomeDate == weekdayRange.length)
result = YES;

return result;
}

#pragma mark - Date Components With Calendar
/**
* Returns the era of the receiver from a given calendar
Expand Down

0 comments on commit 63bd4d8

Please sign in to comment.