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:
FuelBoard Contributor
2026-08-13 15:10:23 +01:00
parent 490c343fd5
commit 2409b71f2f
4 changed files with 51 additions and 7 deletions
+16
View File
@@ -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 {