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

    r14052 r14341  
    2424
    2525#import "InfoActivityViewController.h"
     26#import "NSApplicationAdditions.h"
    2627#import "NSStringAdditions.h"
    2728#import "PiecesView.h"
     
    186187        [fDateAddedField setObjectValue: [torrent dateAdded]];
    187188       
    188         [fDownloadTimeField setStringValue: [NSString timeString: [torrent secondsDownloading] showSeconds: YES]];
    189         [fSeedTimeField setStringValue: [NSString timeString: [torrent secondsSeeding] showSeconds: YES]];
     189        if ([NSApp isOnYosemiteOrBetter]) {
     190            static NSDateComponentsFormatter *timeFormatter;
     191            static dispatch_once_t onceToken;
     192            dispatch_once(&onceToken, ^{
     193                timeFormatter = [NSDateComponentsFormatter new];
     194                timeFormatter.unitsStyle = NSDateComponentsFormatterUnitsStyleShort;
     195                timeFormatter.allowedUnits = NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
     196                timeFormatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropLeading;
     197            });
     198           
     199            [fDownloadTimeField setStringValue: [timeFormatter stringFromTimeInterval:[torrent secondsDownloading]]];
     200            [fSeedTimeField setStringValue: [timeFormatter stringFromTimeInterval:[torrent secondsSeeding]]];
     201        }
     202        else {
     203            [fDownloadTimeField setStringValue: [NSString timeString: [torrent secondsDownloading] includesTimeRemainingPhrase:NO showSeconds: YES]];
     204            [fSeedTimeField setStringValue: [NSString timeString: [torrent secondsSeeding] includesTimeRemainingPhrase:NO showSeconds: YES]];
     205        }
    190206       
    191207        [fPiecesView updateView];
Note: See TracChangeset for help on using the changeset viewer.