Skip to content
Browse files

Workaround for a bug in iTC that could cause duplicate weekly reports

  • Loading branch information...
1 parent fd918a9 commit 7991dea4bd17c481726cf765d3b88e02d1862c77 Ole Zorn committed Mar 26, 2012
Showing with 17 additions and 0 deletions.
  1. +17 −0 Classes/ReportDownloadOperation.m
View
17 Classes/ReportDownloadOperation.m
@@ -183,6 +183,23 @@ - (void)main
if (originalFilename && [reportCSV length] > 0) {
//Parse report CSV:
Report *report = [Report insertNewReportWithCSV:reportCSV inAccount:account];
+
+ //Check if the downloaded report is actually the one we expect
+ //(mostly to work around a bug in iTC that causes the wrong weekly report to be downloaded):
+ NSString *downloadedReportDateString = nil;
+ if ([report isKindOfClass:[WeeklyReport class]]) {
+ WeeklyReport *weeklyReport = (WeeklyReport *)report;
+ downloadedReportDateString = [dateFormatter stringFromDate:weeklyReport.endDate];
+ } else {
+ downloadedReportDateString = [dateFormatter stringFromDate:report.startDate];
+ }
+ if (![reportDateString isEqualToString:downloadedReportDateString]) {
+ NSLog(@"Downloaded report has incorrect date, ignoring");
+ [[report managedObjectContext] deleteObject:report];
+ report = nil;
+ continue;
+ }
+
if (report && originalFilename) {
NSManagedObject *originalReport = [NSEntityDescription insertNewObjectForEntityForName:@"ReportCSV" inManagedObjectContext:moc];
[originalReport setValue:reportCSV forKey:@"content"];

0 comments on commit 7991dea

Please sign in to comment.
Something went wrong with that request. Please try again.