Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bug that caused incorrect dates when selecting previous or next…

… months' days. Removed log messages.
  • Loading branch information...
commit cbcb4943b2e67888638122c35949ce011506b063 1 parent d0b9cb5
@ocrickard authored
View
37 OCCalendarView/OCCalendarView.m
@@ -18,7 +18,7 @@ - (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame {
}
- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(OCArrowPosition)arrowPos {
- NSLog(@"Arrow Position: %u", arrowPos);
+ //NSLog(@"Arrow Position: %u", arrowPos);
// CGRect frame = CGRectMake(p.x - 390*0.5, p.y - 31.4, 390, 270);
self = [super initWithFrame:frame];
@@ -140,6 +140,8 @@ - (NSDate *)getStartDate {
int day = 1;
int month = currentMonth;
int year = currentYear;
+
+ //NSLog(@"startCurrentMonth:%d", currentMonth);
//Get the first day of the month
NSDateComponents *dateParts = [[NSDateComponents alloc] init];
@@ -156,17 +158,23 @@ - (NSDate *)getStartDate {
forDate:dateOnFirst].length;
if(startPoint.y == 0 && startPoint.x+1 < weekdayOfFirst) {
- day = startPoint.x - weekdayOfFirst+2;
+ day = startPoint.x - weekdayOfFirst + 2;
} else {
int countDays = 1;
for (int i = 0; i < 6; i++) {
for(int j = 0; j < 7; j++) {
int dayNumber = i * 7 + j;
- if(dayNumber >= (weekdayOfFirst - 1) && day <= numDaysInMonth) {
+ if(dayNumber >= (weekdayOfFirst - 1)) {
if(i == startPoint.y && j == startPoint.x) {
day = countDays;
}
++countDays;
+ } else if(countDays > numDaysInMonth) {
+ if(i == startPoint.y && j == startPoint.x) {
+ day = (countDays - numDaysInMonth);
+ month = currentMonth + 1;
+ }
+ countDays++;
}
}
}
@@ -184,9 +192,13 @@ - (NSDate *)getStartDate {
- (NSDate *)getEndDate {
CGPoint endPoint = [selectionView endPoint];
+ //NSLog(@"endPoint:(%f,%f)", endPoint.x, endPoint.y);
+
int day = 1;
int month = currentMonth;
int year = currentYear;
+
+ //NSLog(@"endCurrentMonth:%d", currentMonth);
//Get the first day of the month
NSDateComponents *dateParts = [[NSDateComponents alloc] init];
@@ -202,17 +214,25 @@ - (NSDate *)getEndDate {
inUnit:NSMonthCalendarUnit
forDate:dateOnFirst].length;
if(endPoint.y == 0 && endPoint.x+1 < weekdayOfFirst) {
- day = endPoint.x - weekdayOfFirst+2;
+ day = endPoint.x - weekdayOfFirst + 2;
} else {
int countDays = 1;
for (int i = 0; i < 6; i++) {
for(int j = 0; j < 7; j++) {
int dayNumber = i * 7 + j;
- if(dayNumber >= (weekdayOfFirst - 1) && day <= numDaysInMonth) {
+ if(dayNumber >= (weekdayOfFirst - 1) && countDays <= numDaysInMonth) {
if(i == endPoint.y && j == endPoint.x) {
day = countDays;
+
+ //NSLog(@"endDay:%d", day);
}
++countDays;
+ } else if(countDays > numDaysInMonth) {
+ if(i == endPoint.y && j == endPoint.x) {
+ day = (countDays - numDaysInMonth);
+ month = currentMonth + 1;
+ }
+ countDays++;
}
}
}
@@ -228,6 +248,8 @@ - (NSDate *)getEndDate {
}
- (void)setStartDate:(NSDate *)sDate {
+ //NSLog(@"setStartDate");
+
NSDateComponents *sComponents = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:sDate];
if([sComponents month] != currentMonth) {
@@ -281,6 +303,7 @@ - (void)setStartDate:(NSDate *)sDate {
}
- (void)setEndDate:(NSDate *)eDate {
+ //NSLog(@"setEndDate");
NSDateComponents *eComponents = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:eDate];
if([eComponents month] != currentMonth) {
@@ -385,7 +408,7 @@ - (void)drawRect:(CGRect)rect
}
if([daysView addExtraRow]) {
- NSLog(@"Added extra row");
+ //NSLog(@"Added extra row");
[roundedRectanglePath moveToPoint: CGPointMake(42, 267.42)];
[roundedRectanglePath addCurveToPoint: CGPointMake(52, 278.4) controlPoint1: CGPointMake(42, 273.49) controlPoint2: CGPointMake(46.48, 278.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(361.5, 278.4)];
@@ -411,7 +434,7 @@ - (void)drawRect:(CGRect)rect
[roundedRectanglePath addLineToPoint: CGPointMake(52, 43.9)];
[roundedRectanglePath addCurveToPoint: CGPointMake(42, 53.9) controlPoint1: CGPointMake(46.48, 43.9) controlPoint2: CGPointMake(42, 48.38)];
[roundedRectanglePath addLineToPoint: CGPointMake(42, 246.4)];
- NSLog(@"did not add extra row");
+ //NSLog(@"did not add extra row");
}
[roundedRectanglePath closePath];
View
6 OCCalendarView/OCCalendarViewController.m
@@ -89,8 +89,10 @@ - (void)setEndDate:(NSDate *)eDate {
}
- (void)removeCalView {
- self.startDate = [calView getStartDate];
- self.endDate = [calView getEndDate];
+ startDate = [[calView getStartDate] retain];
+ endDate = [[calView getEndDate] retain];
+
+ //NSLog(@"startDate:%@ endDate:%@", startDate.description, endDate.description);
[calView removeFromSuperview];
calView = nil;
View
8 OCCalendarView/OCDaysView.m
@@ -54,13 +54,13 @@ - (void)drawRect:(CGRect)rect
NSDateComponents *weekdayComponents = [calendar components:NSWeekdayCalendarUnit fromDate:dateOnFirst];
int weekdayOfFirst = [weekdayComponents weekday];
- NSLog(@"weekdayOfFirst:%d", weekdayOfFirst);
+ //NSLog(@"weekdayOfFirst:%d", weekdayOfFirst);
int numDaysInMonth = [calendar rangeOfUnit:NSDayCalendarUnit
inUnit:NSMonthCalendarUnit
forDate:dateOnFirst].length;
- NSLog(@"month:%d, numDaysInMonth:%d", currentMonth, numDaysInMonth);
+ //NSLog(@"month:%d, numDaysInMonth:%d", currentMonth, numDaysInMonth);
CGContextRef context = UIGraphicsGetCurrentContext();
@@ -130,7 +130,7 @@ - (void)drawRect:(CGRect)rect
if(i == 5) {
didAddExtraRow = YES;
- NSLog(@"didAddExtraRow");
+ //NSLog(@"didAddExtraRow");
}
++day;
@@ -206,7 +206,7 @@ - (void)resetRows {
if(dayNumber >= (weekdayOfFirst - 1) && day <= numDaysInMonth) {
if(i == 5) {
didAddExtraRow = YES;
- NSLog(@"didAddExtraRow");
+ //NSLog(@"didAddExtraRow");
}
++day;
}
View
1  OCCalendarView/OCSelectionView.m
@@ -73,6 +73,7 @@ - (void)drawRect:(CGRect)rect
if(endCellY == i) {
thisRowEndCell = endCellX;
+// } else {
if (startCellY > endCellY) {
thisRowStartCell = endCellX; thisRowEndCell = 6;
}
Please sign in to comment.
Something went wrong with that request. Please try again.