diff --git a/iphone/Maps/Categories/TimeUtils.h b/iphone/Maps/Categories/TimeUtils.h index a54675841b..78d99ce4be 100644 --- a/iphone/Maps/Categories/TimeUtils.h +++ b/iphone/Maps/Categories/TimeUtils.h @@ -3,7 +3,6 @@ @interface NSDateFormatter (Utils) -+ (NSString *)estimatedArrivalTimeWithSeconds:(NSNumber *)seconds; -+ (NSDate *)dateWithString:(NSString *)dateString; ++ (NSString *)estimatedArrivalTimeWithSeconds:(NSTimeInterval)seconds; @end \ No newline at end of file diff --git a/iphone/Maps/Categories/TimeUtils.mm b/iphone/Maps/Categories/TimeUtils.mm index 4255433022..b5929fac70 100644 --- a/iphone/Maps/Categories/TimeUtils.mm +++ b/iphone/Maps/Categories/TimeUtils.mm @@ -1,27 +1,25 @@ - #import "TimeUtils.h" +#import "Common.h" @implementation NSDateFormatter (Seconds) -+ (NSString *)estimatedArrivalTimeWithSeconds:(NSNumber *)seconds ++ (NSString *)estimatedArrivalTimeWithSeconds:(NSTimeInterval)seconds { - NSInteger const ti = [seconds integerValue]; - NSInteger const minutes = ti / 60; - NSInteger const hours = minutes / 60; - return [NSString stringWithFormat:@"%ld:%02ld", (long)hours, (long)(minutes % 60)]; -} - -+ (NSDate *)dateWithString:(NSString *)dateString -{ - static NSDateFormatter * dateFormatter; - if (!dateFormatter) + if (isIOS7) { - dateFormatter = [NSDateFormatter new]; - dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; - dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss"; + NSInteger const minutes = seconds / 60; + NSInteger const hours = minutes / 60; + return [NSString stringWithFormat:@"%ld:%02ld", (long)hours, (long)(minutes % 60)]; + } + else + { + NSDateComponentsFormatter * formatter = [[NSDateComponentsFormatter alloc] init]; + formatter.allowedUnits = NSCalendarUnitMinute | NSCalendarUnitHour | NSCalendarUnitDay; + formatter.maximumUnitCount = 2; + formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleAbbreviated; + formatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropAll; + return [formatter stringFromTimeInterval:seconds]; } - NSDate * date = [dateFormatter dateFromString:dateString]; - return date; } @end \ No newline at end of file diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm index f0413763c0..e1b08b20c5 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm @@ -149,7 +149,7 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { self.navigationInfo = info; if (self.routingInfoPageControl.currentPage == 0) { - self.timeLabel.text = [NSDateFormatter estimatedArrivalTimeWithSeconds:@(info.timeToTarget)]; + self.timeLabel.text = [NSDateFormatter estimatedArrivalTimeWithSeconds:info.timeToTarget]; } else { diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/MWMRoutePreview.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/MWMRoutePreview.mm index e03cde6e28..9cde0d86de 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/MWMRoutePreview.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/MWMRoutePreview.mm @@ -323,7 +323,7 @@ static CGFloat constexpr kAdditionalHeight = 20.; - (void)updateNavigationInfo:(MWMNavigationDashboardEntity *)info { - NSString * eta = [NSDateFormatter estimatedArrivalTimeWithSeconds:@(info.timeToTarget)]; + NSString * eta = [NSDateFormatter estimatedArrivalTimeWithSeconds:info.timeToTarget]; NSString * resultString = [NSString stringWithFormat:@"%@ • %@ %@", eta, info.targetDistance, info.targetUnits]; NSMutableAttributedString * result =