Changeset 20757
- Timestamp:
- 08/24/2007 01:48:06 PM (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m
r20756 r20757 199 199 + (NSString *)stringForTimeInterval:(NSTimeInterval)interval showingSeconds:(BOOL)showSeconds abbreviated:(BOOL)abbreviate approximated:(BOOL)approximate 200 200 { 201 NSString *timeString = nil;202 201 NSTimeInterval workInterval = interval; 203 202 int weeks = 0, days = 0, hours = 0, minutes = 0; … … 247 246 248 247 //assemble the parts 248 NSMutableArray *parts = [NSMutableArray arrayWithCapacity:5]; 249 249 if (approximate) { 250 //We want only one of these. For example, 5 weeks, 5 days, 5 hours, 5 minutes, and 5 seconds should just be “5 weeks”. 250 251 if (weeks) 251 timeString = weeksString;252 [parts addObject:weeksString]; 252 253 else if (days) 253 timeString = daysString;254 [parts addObject:daysString]; 254 255 else if (hours) 255 timeString = hoursString;256 [parts addObject:hoursString]; 256 257 else if (minutes) 257 timeString = minutesString;258 else if (s econds && showSeconds)259 timeString = secondsString;258 [parts addObject:minutesString]; 259 else if (showSeconds && (seconds >= 0.01)) 260 [parts addObject:secondsString]; 260 261 } else { 262 //We want all of these that aren't zero. 261 263 if (weeks) 262 timeString = [NSString stringWithFormat: @"%@ %@ %@ %@", weeksString, daysString, hoursString, minutesString]; 263 else if (days) 264 timeString = [NSString stringWithFormat: @"%@ %@ %@", daysString, hoursString, minutesString]; 265 else if (hours) 266 timeString = [NSString stringWithFormat: @"%@ %@ ", hoursString, minutesString]; 267 else if (minutes) 268 timeString = minutesString; 269 270 if (showSeconds) { 271 if (timeString) 272 timeString = [timeString stringByAppendingFormat: @" %@", secondsString]; 273 else if (seconds) 274 timeString = secondsString; 275 } 264 [parts addObject:weeksString]; 265 if (days) 266 [parts addObject:daysString]; 267 if (hours) 268 [parts addObject:hoursString]; 269 if (minutes) 270 [parts addObject:minutesString]; 271 if (showSeconds && (seconds >= 0.01)) 272 [parts addObject:secondsString]; 276 273 } 277 274 278 return timeString ? timeString : @"";275 return [parts componentsJoinedByString:@" "]; 279 276 } 280 277