Ilya Laktyushin 03a84fda99 Update API
2020-06-16 11:43:15 +03:00

28 lines
949 B
Swift

import Foundation
import MapKit
import TelegramPresentationData
private var sharedShortDistanceFormatter: MKDistanceFormatter?
public func shortStringForDistance(strings: PresentationStrings, distance: Int32) -> String {
let distanceFormatter: MKDistanceFormatter
if let currentDistanceFormatter = sharedShortDistanceFormatter {
distanceFormatter = currentDistanceFormatter
} else {
distanceFormatter = MKDistanceFormatter()
distanceFormatter.unitStyle = .abbreviated
sharedShortDistanceFormatter = distanceFormatter
}
let locale = localeWithStrings(strings)
if distanceFormatter.locale != locale {
distanceFormatter.locale = locale
}
let distance = max(1, distance)
var result = distanceFormatter.string(fromDistance: Double(distance))
if result.hasPrefix("0 ") {
result = result.replacingOccurrences(of: "0 ", with: "1 ")
}
return result
}