mirror of
https://github.com/tonytins/amtkstat.git
synced 2026-10-24 13:42:51 -04:00
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.
This commit is contained in:
parent
3533e5d4b8
commit
915d0ec2dc
3 changed files with 60 additions and 10 deletions
|
|
@ -54,7 +54,15 @@ struct ContentView: View {
|
|||
TableColumn("Train", value: \TrainStatusRow.routeName)
|
||||
TableColumn("To", value: \TrainStatusRow.origin)
|
||||
TableColumn("From", value: \TrainStatusRow.destination)
|
||||
TableColumn("Status", value: \TrainStatusRow.status)
|
||||
TableColumn("Status") {
|
||||
(row: TrainStatusRow) in
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 0)
|
||||
.fill(row.status.color)
|
||||
Text(row.status.descrption)
|
||||
.foregroundColor(Color.white)
|
||||
}
|
||||
}
|
||||
TableColumn("Track", value: \TrainStatusRow.platform)
|
||||
}.frame(minWidth: 600)
|
||||
.overlay(alignment: .bottomTrailing) {
|
||||
|
|
@ -129,28 +137,25 @@ struct ContentView: View {
|
|||
}
|
||||
}
|
||||
|
||||
func isOnTime(arr: String?, schArr: String?) -> String {
|
||||
func isOnTime(arr: String?, schArr: String?) -> TrainLateness {
|
||||
let amtrakDate = AmtrakDateFormatting()
|
||||
|
||||
guard
|
||||
let actualDate = amtrakDate.parsedDate(from: arr),
|
||||
let scheduledDate = amtrakDate.parsedDate(from: schArr)
|
||||
else {
|
||||
return "On Time"
|
||||
return .unknown
|
||||
}
|
||||
|
||||
let differenceInMinutes = Int(actualDate.timeIntervalSince(scheduledDate) / 60)
|
||||
|
||||
switch differenceInMinutes {
|
||||
case -1...1:
|
||||
return "On Time"
|
||||
return .onTime
|
||||
case ..<0:
|
||||
return "\(-differenceInMinutes) min early"
|
||||
case 0..<60:
|
||||
return "\(differenceInMinutes) min late"
|
||||
return .early(minutes: -differenceInMinutes)
|
||||
default:
|
||||
let hours = differenceInMinutes / 60
|
||||
return "\(hours) hr late"
|
||||
return .late(minutes: differenceInMinutes)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue