Ignore:
Timestamp:
Oct 17, 2014, 5:12:00 AM (8 years ago)
Author:
livings124
Message:

Yosemite: use NSDateComponentsFormatter instead of custom time string code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/NSStringAdditions.m

    r14045 r14341  
    154154}
    155155
    156 + (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds
    157 {
    158     return [NSString timeString: seconds showSeconds: showSeconds maxFields: NSUIntegerMax];
    159 }
    160 
    161 + (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds maxFields: (NSUInteger) max
    162 {
     156+ (NSString *) timeString: (uint64_t) seconds includesTimeRemainingPhrase: (BOOL) includesTimeRemainingPhrase showSeconds: (BOOL) showSeconds
     157{
     158    return [NSString timeString: seconds
     159    includesTimeRemainingPhrase: includesTimeRemainingPhrase
     160                    showSeconds: showSeconds
     161                      maxFields: NSUIntegerMax];
     162}
     163
     164+ (NSString *) timeString: (uint64_t) seconds includesTimeRemainingPhrase: (BOOL) includesTimeRemainingPhrase showSeconds: (BOOL) showSeconds maxFields: (NSUInteger) max
     165{
     166    NSAssert(![NSApp isOnYosemiteOrBetter], @"you should be using NSDateComponentsFormatter on >= 10.10");
    163167    NSParameterAssert(max > 0);
    164168   
     
    201205        [timeArray addObject: [NSString stringWithFormat: NSLocalizedString(@"%u sec", "time string"), remaining]];
    202206   
    203     return [timeArray componentsJoinedByString: @" "];
     207    NSString * timeString = [timeArray componentsJoinedByString: @" "];
     208   
     209    if (includesTimeRemainingPhrase) {
     210        timeString = [NSString stringWithFormat: NSLocalizedString(@"%@ remaining", "time remaining string"), timeString];
     211    }
     212   
     213    return timeString;
    204214}
    205215
Note: See TracChangeset for help on using the changeset viewer.