Labels: pluralize miles (1 mile) and show true distances in the chosen unit (5 mi = 8 km) across Alerts/Stations pickers + captions
This commit is contained in:
@@ -105,6 +105,22 @@ enum DistanceUnit: String, Codable, CaseIterable, Identifiable {
|
||||
}
|
||||
}
|
||||
|
||||
/// Full word for a specific value — pluralizes miles ("1 mile" vs
|
||||
/// "5 miles"); metric is always "km".
|
||||
func label(for value: Double) -> String {
|
||||
switch self {
|
||||
case .miles: return value == 1 ? "mile" : "miles"
|
||||
case .kilometers: return "km"
|
||||
}
|
||||
}
|
||||
|
||||
/// A whole-mile distance (as stored/used by search + Live Activity)
|
||||
/// shown in this unit, rounded to a whole number for picker labels:
|
||||
/// 5 miles -> "5" (miles unit) or "8" (km unit).
|
||||
func displayMiles(_ miles: Int) -> Int {
|
||||
Int(fromKM(Double(miles) * 1.60934).rounded())
|
||||
}
|
||||
|
||||
/// Convert a value expressed in this unit to km.
|
||||
func toKM(_ value: Double) -> Double {
|
||||
switch self {
|
||||
|
||||
Reference in New Issue
Block a user