Skip to content

Instantly share code, notes, and snippets.

@sck
Created August 8, 2013 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sck/6187509 to your computer and use it in GitHub Desktop.
Save sck/6187509 to your computer and use it in GitHub Desktop.
c&p progress estimation
// calculate time left if we're more than 10% done
NSString *timeString = nil;
float percentLeft = (float)([theCanvas eventCount]-[theCanvas currentPlaybackEvent])/(float)[theCanvas eventCount];
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
if( percentLeft < 0.9f && now-_lastTimeWeEstimated > 5.0 ) {
_lastTimeWeEstimated = now;
NSTimeInterval timeLeft = (now-_exportStartTime)*(percentLeft/(1.0f-percentLeft));
int hours = timeLeft/(60.0*60.0);
timeLeft -= (double)hours*60.0*60.0;
int mins = timeLeft/60.0;
timeLeft -= (double)mins*60.0;
int secs = timeLeft;
if( mins < 1 )
timeString = NSLocalizedString(@"less than a minute",@"less than a minute");
else
timeString = [NSString stringWithFormat:@"-%d:%02d:%02d",hours,mins,secs];
//[_exportTimeText setStringValue:timeString];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment