Permalink
Browse files

Show time elapsed when all done.

  • Loading branch information...
1 parent af025e4 commit 9f6ecd224aac51e5689b29f14a70f992270526da @aglee committed Jun 6, 2014
Showing with 18 additions and 1 deletion.
  1. +18 −1 WWDCDownloader/WWDCWebsiteInteractionController.m
@@ -22,6 +22,8 @@ @implementation WWDCWebsiteInteractionController {
NSUInteger _totalNumberToDownload;
NSUInteger _numberCompleted;
NSUInteger _numberFailed;
+
+ NSTimeInterval _startTimestamp;
}
- (id) init {
@@ -58,6 +60,7 @@ - (IBAction) download:(id) sender {
return;
}
+ _startTimestamp = [[NSDate date] timeIntervalSince1970];
_totalNumberToDownload = _numberCompleted = _numberFailed = 0;
for (WWDCSession *session in _sessions) {
@@ -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;
@zadr

zadr Jun 7, 2014

It would be neat to use NSDateComponentsFormatter on 10.10 here!

@aglee

aglee Jun 7, 2014

Owner

Nice to know -- thanks!

+
+ return [NSString stringWithFormat:@"Time elapsed: %02ld:%02ld:%02ld", hours, minutes, seconds];
}
- (void) findDownloadsForSession:(WWDCSession *)session {

0 comments on commit 9f6ecd2

Please sign in to comment.