Created
April 30, 2014 16:37
-
-
Save jonahsiegle/054f36dca9f961dd3d59 to your computer and use it in GitHub Desktop.
Converts NSTimeInterval into a verbal NSString format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)readableTimeWithDuration:(NSTimeInterval)timeDuration{ | |
NSUInteger roundedTime = round(timeDuration); | |
unsigned long days = roundedTime / 86400; | |
unsigned long hours = roundedTime / 3600; | |
unsigned long minutes = (roundedTime / 60) % 60; | |
NSString *dayLabel = days > 1 ? @"Days" : @"Day"; | |
NSString *hourLabel = hours > 1 ? @"Hours" : @"Hour"; | |
NSString *minuteLabel = minutes > 1 ? @"Minutes" : @"Minute"; | |
NSString *string = (days>0) ? [NSString stringWithFormat:@"%lu %@, %lu %@", | |
days, dayLabel, hours, hourLabel] : [NSString stringWithFormat:@"%lu %@, %lu %@", | |
hours, hourLabel, minutes, minuteLabel]; | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment