Show local station time; reuse date formatter

- Added localTime(timeZone:) and updateTime(timeZone:) to AmtrakDateFormatting to format the current time for a given timezone.
- In ContentView, make AmtrakDateFormatting is now a shared property with localTimeZone being used at the bottom to show "It is <time> at <station> station".
- trainStatus now saves the station name and timezone (avoiding repeated formatter instantiation) and isOnTime uses the shared formatter.
This commit is contained in:
Tony Bark 2026-08-24 03:09:49 -04:00
parent 791f261fc7
commit a43eefadc1
2 changed files with 19 additions and 5 deletions

View file

@ -35,6 +35,17 @@ struct AmtrakDateFormatting {
return timeFormatter.string(from: date)
}
func localTime(timeZone: TimeZone?) -> String {
let now = Date()
timeFormatter.timeZone = timeZone
return timeFormatter.string(from: now)
}
func updateTime(timeZone: TimeZone?) {
let now = Date()
timeFormatter.timeZone = timeZone
}
func date(from isoString: String?) -> String? {
guard let isoString, !isoString.isEmpty, let date = isoFormatter.date(
from: isoString) else {