mirror of
https://github.com/tonytins/amtkstat.git
synced 2026-10-24 05:32:54 -04:00
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:
parent
791f261fc7
commit
a43eefadc1
2 changed files with 19 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue