Skip to content

Commit ea1a5a1

Browse files
committed
Fixed bug posted by girishnair12345: "setCurrentDate doesnt work properly #4"
1 parent 1b16fc9 commit ea1a5a1

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

ios_calendar/Sources/CalendarView.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ - (void)setCurrentDate:(NSDate *)date
223223
currentMonth = [components month];
224224
currentYear = [components year];
225225

226+
switch (type) {
227+
case CTDay:
228+
[self generateDayRects];
229+
break;
230+
case CTYear:
231+
[self generateYearRects];
232+
break;
233+
default:
234+
break;
235+
}
236+
226237
_currentDate = date;
227238

228239
if (![_currentDate isEqualToDate:date]) {

ios_calendar/Sources/NSDate+CalendarView.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ - (NSUInteger)getLastDayOfMonth
2020

2121
- (NSInteger)getWeekdayOfFirstDayOfMonth
2222
{
23-
NSTimeZone *timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
24-
23+
NSTimeZone *timeZone = [NSTimeZone localTimeZone];
24+
2525
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
2626
[calendar setTimeZone:timeZone];
2727
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:self];

ios_calendar/ViewController.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ - (void)viewDidLoad
3434

3535
self.calendarView.calendarDelegate = self;
3636

37-
// For testing setCurrentDate property
37+
// // For testing setCurrentDate property
3838
// NSDate *d = [NSDate dateWithTimeIntervalSinceNow:-99656988];
3939
// NSLog(@"%@", d);
4040
// [self.calendarView setCurrentDate:d];
41+
42+
// NSDateComponents *comps = [[NSDateComponents alloc] init];
43+
// comps.year = 2015;
44+
// comps.month= 1;
45+
// comps.day = 1;
46+
// NSDate *toDate = [[NSCalendar currentCalendar] dateFromComponents:comps];
47+
// [self.calendarView setCurrentDate:toDate];
4148
}
4249

4350
- (void)didChangeCalendarDate:(NSDate *)date

0 commit comments

Comments
 (0)