Skip to content

Commit

Permalink
Future or past is really today and not the provided date
Browse files Browse the repository at this point in the history
  • Loading branch information
ipodishima committed Dec 2, 2014
1 parent a14bd51 commit 284c337
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions THCalendarDatePicker/THDatePickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ @interface THDatePickerViewController () {
@property (nonatomic, strong) NSDate * firstOfCurrentMonth;
@property (nonatomic, strong) THDateDay * currentDay;
@property (nonatomic, strong) NSDate * internalDate;
@property (nonatomic, strong) NSDate * today;

@property (weak, nonatomic) IBOutlet UILabel *monthLabel;
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;
@property (weak, nonatomic) IBOutlet UIButton *prevBtn;
Expand Down Expand Up @@ -261,6 +263,7 @@ - (void)setDate:(NSDate *)date {
_date = date;
_dateNoTime = !date ? nil : [self dateWithOutTime:date];
self.internalDate = [_dateNoTime dateByAddingTimeInterval:0];
self.today = [self dateWithOutTime:[NSDate date]];
}

- (NSDate *)date {
Expand All @@ -281,7 +284,7 @@ - (NSDate *)date {
- (BOOL)shouldOkBeEnabled {
if (_autoCloseOnSelectDate)
return YES;
float diff = [self.internalDate timeIntervalSinceDate:_dateNoTime];
float diff = fabs([self.internalDate timeIntervalSinceDate:self.today]);
return (self.internalDate && _dateNoTime && diff >= 0)
|| (self.internalDate && !_dateNoTime)
|| (!self.internalDate && _dateNoTime);
Expand Down Expand Up @@ -464,7 +467,7 @@ - (void) hideClearButton {
#pragma mark - Date Utils

- (BOOL)dateInFutureAndShouldBeDisabled:(NSDate *)dateToCompare {
NSDate *currentDate = [self internalDate];
NSDate *currentDate = [self today];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSInteger comps = (NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear);
currentDate = [calendar dateFromComponents:[calendar components:comps fromDate:currentDate]];
Expand Down

0 comments on commit 284c337

Please sign in to comment.