amtkstat/Sources/AmtrakStatus/TrainLateness.swift
Tony Bark 915d0ec2dc Train status is now coloured coded for your convenience
- Introduced TrainLateness enum to represent on-time, early, late (with minutes), and unknown states, including description text, color, and formatting logic.
- Replaced TrainStatusRow.status String with TrainLateness and update ContentView to render a colored status pill and to return TrainLateness from isOnTime.
2026-08-23 21:23:45 -04:00

45 lines
1,017 B
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
guard hours > 0 else {
return "\(minutes) mins"
}
return "\(hours) hr late"
}
}