Skip to content

Commit

Permalink
Show time elapsed when all done.
Browse files Browse the repository at this point in the history
  • Loading branch information
aglee committed Jun 6, 2014
1 parent af025e4 commit 9f6ecd2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion WWDCDownloader/WWDCWebsiteInteractionController.m
Expand Up @@ -22,6 +22,8 @@ @implementation WWDCWebsiteInteractionController {
NSUInteger _totalNumberToDownload;
NSUInteger _numberCompleted;
NSUInteger _numberFailed;

NSTimeInterval _startTimestamp;
}

- (id) init {
Expand Down Expand Up @@ -58,6 +60,7 @@ - (IBAction) download:(id) sender {
return;
}

_startTimestamp = [[NSDate date] timeIntervalSince1970];
_totalNumberToDownload = _numberCompleted = _numberFailed = 0;

for (WWDCSession *session in _sessions) {
Expand Down Expand Up @@ -146,9 +149,23 @@ - (void) updateDownloadProgressBar
self.downloadProgressBar.doubleValue = _numberCompleted + _numberFailed;
if (_numberCompleted + _numberFailed == _totalNumberToDownload) {
[self.downloadProgressBar setHidden:YES];

NSTimeInterval endTimestamp = [[NSDate date] timeIntervalSince1970];
self.statusTextField.stringValue = [self stringForTimeInterval:(endTimestamp - _startTimestamp)];
} else {
[self putNumberCompletedInStatusField];
}
}

[self putNumberCompletedInStatusField];
- (NSString *)stringForTimeInterval:(NSTimeInterval)interval
{
long totalSeconds = interval;
long hours = totalSeconds / (60*60);
long remainder = totalSeconds % (60*60);
long minutes = remainder / 60;
long seconds = remainder % 60;

This comment has been minimized.

Copy link
@zadr

zadr Jun 7, 2014

It would be neat to use NSDateComponentsFormatter on 10.10 here!

This comment has been minimized.

Copy link
@aglee

aglee Jun 7, 2014

Author Owner

Nice to know -- thanks!


return [NSString stringWithFormat:@"Time elapsed: %02ld:%02ld:%02ld", hours, minutes, seconds];
}

- (void) findDownloadsForSession:(WWDCSession *)session {
Expand Down

0 comments on commit 9f6ecd2

Please sign in to comment.