Skip to content

Commit

Permalink
Merge pull request #235 from roostr/master
Browse files Browse the repository at this point in the history
Fixed #234 Clicking month bar shows report that's off by one month
  • Loading branch information
omz committed Jan 6, 2013
2 parents 73ba06d + c7c1cea commit 246409c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions Classes/SalesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,18 @@ - (void)reloadData
for (Report *dailyReport in sortedDailyReports) {
NSDateComponents *dateComponents = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit fromDate:dailyReport.startDate];
if (!prevDateComponents || (dateComponents.month != prevDateComponents.month || dateComponents.year != prevDateComponents.year)) {
if (reportsInCurrentMonth) {
ReportCollection *monthCollection = [[[ReportCollection alloc] initWithReports:reportsInCurrentMonth] autorelease];
monthCollection.title = [monthFormatter stringFromDate:dailyReport.startDate];
[sortedCalendarMonthReports addObject:monthCollection];
}
// New month discovered. Make a new ReportCollection to gather all the daily reports in this month.
reportsInCurrentMonth = [NSMutableArray array];
[reportsInCurrentMonth addObject:dailyReport];
ReportCollection *monthCollection = [[[ReportCollection alloc] initWithReports:reportsInCurrentMonth] autorelease];
monthCollection.title = [monthFormatter stringFromDate:dailyReport.startDate];
[sortedCalendarMonthReports addObject:monthCollection];
} else {
// This report is from the same month as the previous report. Append the daily report to the existing collection.
[reportsInCurrentMonth addObject:dailyReport];
}
[reportsInCurrentMonth addObject:dailyReport];
prevDateComponents = dateComponents;
}
if ([reportsInCurrentMonth count] > 0) {
ReportCollection *monthCollection = [[[ReportCollection alloc] initWithReports:reportsInCurrentMonth] autorelease];
monthCollection.title = [monthFormatter stringFromDate:[monthCollection firstReport].startDate];
[sortedCalendarMonthReports addObject:monthCollection];
}

// Group daily reports by fiscal month:
[sortedFiscalMonthReports removeAllObjects];
Expand Down

0 comments on commit 246409c

Please sign in to comment.