mirror of
https://github.com/tonytins/amtkstat.git
synced 2026-10-24 13:42:51 -04:00
Compare commits
2 commits
dc464de1c4
...
ca60e36ea2
| Author | SHA1 | Date | |
|---|---|---|---|
| ca60e36ea2 | |||
| c699007cbf |
9 changed files with 587 additions and 561 deletions
|
|
@ -9,7 +9,7 @@ let package = Package(
|
||||||
.package(
|
.package(
|
||||||
url: "https://github.com/moreSwift/swift-cross-ui",
|
url: "https://github.com/moreSwift/swift-cross-ui",
|
||||||
.upToNextMinor(from: "0.7.0"),
|
.upToNextMinor(from: "0.7.0"),
|
||||||
),
|
)
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.executableTarget(
|
.executableTarget(
|
||||||
|
|
@ -18,6 +18,6 @@ let package = Package(
|
||||||
.product(name: "SwiftCrossUI", package: "swift-cross-ui"),
|
.product(name: "SwiftCrossUI", package: "swift-cross-ui"),
|
||||||
.product(name: "DefaultBackend", package: "swift-cross-ui"),
|
.product(name: "DefaultBackend", package: "swift-cross-ui"),
|
||||||
],
|
],
|
||||||
),
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ enum AmtrakError: Error {
|
||||||
case stationNotFound(String)
|
case stationNotFound(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct TrainStationLookUp: Sendable {
|
struct TrainStationLookUp: Sendable {
|
||||||
var trainNumbers: [String]
|
var trainNumbers: [String]
|
||||||
var timeZone: TimeZone?
|
var timeZone: TimeZone?
|
||||||
|
|
@ -52,7 +51,6 @@ struct AmtrakClient {
|
||||||
.map(String.init) ?? trainId
|
.map(String.init) ?? trainId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func trainStationLookup(stationCode code: String) async throws -> TrainStationLookUp {
|
func trainStationLookup(stationCode code: String) async throws -> TrainStationLookUp {
|
||||||
let reponse = try await fetchStation(code: code)
|
let reponse = try await fetchStation(code: code)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,23 @@ struct AmtrakDateFormatting {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
func parsedDate(from isoString: String?) -> Date? {
|
func parsedDate(from isoString: String?) -> Date? {
|
||||||
guard let isoString, !isoString.isEmpty, let date = isoFormatter.date(
|
guard let isoString, !isoString.isEmpty,
|
||||||
from: isoString) else {
|
let date = isoFormatter.date(
|
||||||
|
from: isoString)
|
||||||
|
else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return isoFormatter.date(from: isoString)
|
return isoFormatter.date(from: isoString)
|
||||||
}
|
}
|
||||||
|
|
||||||
func time(from isoString: String?, in zone: TimeZone?, comparedTo originZone: TimeZone? = nil) -> String? {
|
func time(from isoString: String?, in zone: TimeZone?, comparedTo originZone: TimeZone? = nil)
|
||||||
guard let isoString, !isoString.isEmpty, let date = isoFormatter.date(
|
-> String?
|
||||||
from: isoString) else {
|
{
|
||||||
|
guard let isoString, !isoString.isEmpty,
|
||||||
|
let date = isoFormatter.date(
|
||||||
|
from: isoString)
|
||||||
|
else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,7 +54,6 @@ struct AmtrakDateFormatting {
|
||||||
return "\(formatted) \(abbreviation)"
|
return "\(formatted) \(abbreviation)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func isOnTime(actual: String?, scheduled: String?) -> LateTrain {
|
func isOnTime(actual: String?, scheduled: String?) -> LateTrain {
|
||||||
|
|
||||||
guard
|
guard
|
||||||
|
|
@ -70,7 +75,6 @@ struct AmtrakDateFormatting {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func localTime(timeZone: TimeZone?) -> String {
|
func localTime(timeZone: TimeZone?) -> String {
|
||||||
let now = Date()
|
let now = Date()
|
||||||
timeFormatter.timeZone = timeZone
|
timeFormatter.timeZone = timeZone
|
||||||
|
|
@ -83,8 +87,10 @@ struct AmtrakDateFormatting {
|
||||||
}
|
}
|
||||||
|
|
||||||
func date(from isoString: String?) -> String? {
|
func date(from isoString: String?) -> String? {
|
||||||
guard let isoString, !isoString.isEmpty, let date = isoFormatter.date(
|
guard let isoString, !isoString.isEmpty,
|
||||||
from: isoString) else {
|
let date = isoFormatter.date(
|
||||||
|
from: isoString)
|
||||||
|
else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import SwiftCrossUI
|
||||||
@main
|
@main
|
||||||
struct AmtrakStatusApp: App {
|
struct AmtrakStatusApp: App {
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup("Amtrak Status") {
|
WindowGroup("AMTK Status") {
|
||||||
ContentView()
|
ContentView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import SwiftCrossUI
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import SwiftCrossUI
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@State var client = AmtrakClient()
|
@State var client = AmtrakClient()
|
||||||
|
|
@ -148,7 +147,8 @@ struct ContentView: View {
|
||||||
let trains = try await client.fetchAllTrainStatus(num: number)
|
let trains = try await client.fetchAllTrainStatus(num: number)
|
||||||
for train in trains {
|
for train in trains {
|
||||||
let platform = train.stations?.first(
|
let platform = train.stations?.first(
|
||||||
where: { $0.code == code
|
where: {
|
||||||
|
$0.code == code
|
||||||
},
|
},
|
||||||
)?.platform
|
)?.platform
|
||||||
let row = await trainStatus(
|
let row = await trainStatus(
|
||||||
|
|
@ -201,11 +201,13 @@ struct ContentView: View {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let time = amtrakDate.time(
|
let time =
|
||||||
|
amtrakDate.time(
|
||||||
from: leg?.arr,
|
from: leg?.arr,
|
||||||
in: timeZone,
|
in: timeZone,
|
||||||
comparedTo: originZone
|
comparedTo: originZone
|
||||||
) ?? amtrakDate.time(
|
)
|
||||||
|
?? amtrakDate.time(
|
||||||
from: leg?.schArr,
|
from: leg?.schArr,
|
||||||
in: timeZone,
|
in: timeZone,
|
||||||
comparedTo: originZone
|
comparedTo: originZone
|
||||||
|
|
@ -245,7 +247,8 @@ struct ContentView: View {
|
||||||
|
|
||||||
var calendar = Calendar.current
|
var calendar = Calendar.current
|
||||||
calendar.timeZone = timeZone ?? .current
|
calendar.timeZone = timeZone ?? .current
|
||||||
return calendar
|
return
|
||||||
|
calendar
|
||||||
.compare(
|
.compare(
|
||||||
deparatureDate,
|
deparatureDate,
|
||||||
to: Date(),
|
to: Date(),
|
||||||
|
|
@ -271,7 +274,9 @@ struct ContentView: View {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchTimeZone(forStationCode code: String, cache: inout [String: TimeZone?]) async -> TimeZone? {
|
func fetchTimeZone(forStationCode code: String, cache: inout [String: TimeZone?]) async
|
||||||
|
-> TimeZone?
|
||||||
|
{
|
||||||
if let cached = cache[code] {
|
if let cached = cache[code] {
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ enum LateTrain {
|
||||||
switch self {
|
switch self {
|
||||||
case .onTime:
|
case .onTime:
|
||||||
return "On Time"
|
return "On Time"
|
||||||
case .early(minutes: let minutes):
|
case .early(let minutes):
|
||||||
return "\(Self.formatted(minutes)) early"
|
return "\(Self.formatted(minutes)) early"
|
||||||
case .late(minutes: let minutes):
|
case .late(let minutes):
|
||||||
return "\(Self.formatted(minutes)) late"
|
return "\(Self.formatted(minutes)) late"
|
||||||
case .unknown:
|
case .unknown:
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
17
format.sh
Executable file
17
format.sh
Executable file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/bash
|
||||||
|
##===----------------------------------------------------------------------===##
|
||||||
|
##
|
||||||
|
## This source file is from the Swift Argument Parser open source project
|
||||||
|
##
|
||||||
|
## Copyright (c) 2025 Apple Inc. and the Swift project authors
|
||||||
|
## Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
##
|
||||||
|
## See https://swift.org/LICENSE.txt for license information
|
||||||
|
##
|
||||||
|
##===----------------------------------------------------------------------===##
|
||||||
|
|
||||||
|
echo "Formatting Swift sources in $(pwd)"
|
||||||
|
|
||||||
|
# Run the format / lint commands
|
||||||
|
git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
|
||||||
|
git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel
|
||||||
Loading…
Add table
Add a link
Reference in a new issue