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/TrackerNode.m

    r13251 r14341  
    2424
    2525#import "TrackerNode.h"
     26#import "NSApplicationAdditions.h"
    2627#import "NSStringAdditions.h"
    2728
     
    157158       
    158159        case TR_TRACKER_WAITING:
     160        {
     161            const NSTimeInterval nextAnnounceTimeLeft = fStat.nextAnnounceTime - [[NSDate date] timeIntervalSince1970];
     162           
     163            NSString *timeString;
     164            if ([NSApp isOnYosemiteOrBetter]) {
     165                static NSDateComponentsFormatter *formatter;
     166                static dispatch_once_t onceToken;
     167                dispatch_once(&onceToken, ^{
     168                    formatter = [NSDateComponentsFormatter new];
     169                    formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleAbbreviated;
     170                    formatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropLeading;
     171                    formatter.collapsesLargestUnit = YES;
     172                });
     173               
     174                timeString = [formatter stringFromTimeInterval: nextAnnounceTimeLeft];
     175            }
     176            else {
     177                timeString = [NSString timeString: nextAnnounceTimeLeft includesTimeRemainingPhrase: NO showSeconds: YES];
     178            }
    159179            return [NSString stringWithFormat: NSLocalizedString(@"Next announce in %@", "Tracker next announce"),
    160                     [NSString timeString: fStat.nextAnnounceTime - [[NSDate date] timeIntervalSince1970] showSeconds: YES]];
    161        
     180                    timeString];
     181        }
    162182        case TR_TRACKER_QUEUED:
    163183            return [NSLocalizedString(@"Announce is queued", "Tracker next announce") stringByAppendingEllipsis];
Note: See TracChangeset for help on using the changeset viewer.