mirror of
https://github.com/tonytins/amtkstat.git
synced 2026-10-24 05:32:54 -04:00
- This update adds ISO date/time helpers for Amtrak timestamps, refactors the train table to show arrival time, status, and track details, and tracks the current station context in the UI. - It also hardens station status decoding with a safe fallback to Unknown and simplifies the row model to match the new display.
37 lines
1 KiB
Swift
37 lines
1 KiB
Swift
import Foundation
|
|
|
|
struct AmtrakDateFormatting {
|
|
static let isoFormatter = ISO8601DateFormatter()
|
|
|
|
static let timeFormatter: DateFormatter = {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .none
|
|
formatter.timeStyle = .short
|
|
return formatter
|
|
}()
|
|
|
|
static let dateFormatter: DateFormatter = {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .medium
|
|
formatter.timeStyle = .none
|
|
return formatter
|
|
}()
|
|
|
|
static func time(from isoString: String?) -> String? {
|
|
guard let isoString, !isoString.isEmpty, let date = isoFormatter.date(
|
|
from: isoString) else {
|
|
return nil
|
|
}
|
|
|
|
return timeFormatter.string(from: date)
|
|
}
|
|
|
|
static func date(from isoString: String?) -> String? {
|
|
guard let isoString, !isoString.isEmpty, let date = isoFormatter.date(
|
|
from: isoString) else {
|
|
return nil
|
|
}
|
|
|
|
return dateFormatter.string(from: date)
|
|
}
|
|
}
|