Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Added isDateToday and isDateYesterday
Browse files Browse the repository at this point in the history
  • Loading branch information
shnhrrsn committed Dec 10, 2009
1 parent 12b5441 commit b4da468
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions NSDate/NSDateHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
// Checks whether current date is past date
- (BOOL)isPastDate;

// Checks whether the current date occured today
- (BOOL)isDateToday;

// Checks whether the current date occured yesterday
- (BOOL)isDateYesterday;

// Returns the current date, at midnight
- (NSDate*)midnightDate;

Expand Down
8 changes: 8 additions & 0 deletions NSDate/NSDateHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ - (BOOL)isPastDate {
}
}

- (BOOL)isDateToday {
return [[[NSDate date] midnightDate] isEqual:[self midnightDate]];
}

- (BOOL)isDateYesterday {
return [[[NSDate dateWithTimeIntervalSinceNow:-86400] midnightDate] isEqual:[self midnightDate]];
}

- (NSDate*)midnightDate {
return [[NSCalendar currentCalendar] dateFromComponents:[[NSCalendar currentCalendar] components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:self]];
}
Expand Down

0 comments on commit b4da468

Please sign in to comment.