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

    r13526 r14341  
    197197    [fRatioAllField setStringValue: totalRatioString];
    198198   
    199     [fTimeField setStringValue: [NSString timeString: statsSession.secondsActive showSeconds: NO]];
    200     [fTimeAllField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ total", "stats total"), [NSString timeString: statsAll.secondsActive showSeconds: NO]]];
     199    if ([NSApp isOnYosemiteOrBetter]) {
     200        static NSDateComponentsFormatter *timeFormatter;
     201        static dispatch_once_t onceToken;
     202        dispatch_once(&onceToken, ^{
     203            timeFormatter = [NSDateComponentsFormatter new];
     204            timeFormatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
     205            timeFormatter.maximumUnitCount = 3;
     206            timeFormatter.allowedUnits = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekOfMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute;
     207            timeFormatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropLeading;
     208        });
     209       
     210        [fTimeField setStringValue: [timeFormatter stringFromTimeInterval:statsSession.secondsActive]];
     211        [fTimeAllField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ total", "stats total"), [timeFormatter stringFromTimeInterval:statsAll.secondsActive]]];
     212    }
     213    else {
     214        [fTimeField setStringValue: [NSString timeString: statsSession.secondsActive includesTimeRemainingPhrase:NO showSeconds: NO]];
     215        [fTimeAllField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ total", "stats total"), [NSString timeString: statsAll.secondsActive includesTimeRemainingPhrase:NO showSeconds: NO]]];
     216    }
    201217   
    202218    if (statsAll.sessionCount == 1)
Note: See TracChangeset for help on using the changeset viewer.