amtkstat/Sources/AmtrakStatus/TrainLateness.swift
Tony Bark 79176585b4 Improve train status formatting
This change adds proper singular/plural labels for minutes and hours in the lateness display, fixes green status text contrast for dark mode, and updates the README to credit the Amtrak.js models used as a base.
2026-08-24 20:07:11 -04:00

49 lines
1.2 KiB
Swift

import Foundation
import SwiftCrossUI
enum TrainLateness {
case onTime
case early(minutes: Int)
case late(minutes: Int)
case unknown
var descrption: String {
switch self {
case .onTime:
return "On Time"
case .early(minutes: let minutes):
return "\(Self.formatted(minutes)) early"
case .late(minutes: let minutes):
return "\(Self.formatted(minutes)) late"
case .unknown:
return ""
}
}
var color: Color {
switch self {
case .onTime:
return .green
case .early:
return .blue
case .late:
return .red
case .unknown:
return .gray
}
}
static func formatted(_ minutes: Int) -> String {
let hours = minutes / 60
let remainder = minutes % 60
let minutesPart = "\(minutes) \(minutes.pluralized(singular: "min", plural: "mins"))"
let hoursPart = "\(hours) \(hours.pluralized(singular: "hr", plural: "hrs"))"
guard hours > 0 else {
return minutesPart
}
return hoursPart
}
}