diff --git a/README.md b/README.md index b132b6e..3e9ecff 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ This was intended to solve a rather awkward dilemma. I turned a bunch of online So I created simple frontend that mapped to Dixieland Software's API using Tauri. You could type in simple station code and it'd take you their status board from within the app. Simple, right? Unfortunately, I didn't know how to get it go back to change the station, my attempted UI redesigns kept failing, and I accidentally botched a migration to Tauri 2.0. I'm just not that good with Node. -So it sat abandoned until I discovered [SwiftCrossUI](https://github.com/moreSwift/swift-cross-ui). Now it directly makes use of [Amtraker](https://amtraker.com/)'s API. +So it sat abandoned until I discovered [SwiftCrossUI](https://github.com/moreSwift/swift-cross-ui). Now it directly makes use of [Amtraker](https://amtraker.com/)'s API, based on models ported from [Amtrak.js](https://github.com/piemadd/amtrak). ## ⚖️ License diff --git a/Sources/AmtrakStatus/ContentView.swift b/Sources/AmtrakStatus/ContentView.swift index ea9df2b..08c3708 100644 --- a/Sources/AmtrakStatus/ContentView.swift +++ b/Sources/AmtrakStatus/ContentView.swift @@ -103,7 +103,7 @@ struct ContentView: View { func statusColour(_ color: Color) -> Color { switch color { case .green: - return .black + return .adaptive(light: .white, dark: .black) default: return .white } diff --git a/Sources/AmtrakStatus/Helper.swift b/Sources/AmtrakStatus/Helper.swift new file mode 100644 index 0000000..7ad152e --- /dev/null +++ b/Sources/AmtrakStatus/Helper.swift @@ -0,0 +1,7 @@ +import Foundation + +extension Int { + func pluralized(singular: String, plural: String) -> String { + self == 1 ? singular : plural + } +} diff --git a/Sources/AmtrakStatus/TrainLateness.swift b/Sources/AmtrakStatus/TrainLateness.swift index cd59dd1..ab81940 100644 --- a/Sources/AmtrakStatus/TrainLateness.swift +++ b/Sources/AmtrakStatus/TrainLateness.swift @@ -33,13 +33,17 @@ enum TrainLateness { } } - static func formatted(_ minutes: Int) -> String { let hours = minutes / 60 let remainder = minutes % 60 + + let minutesPart = "\(minutes) \(minutes.pluralized(singular: "min", plural: "mins"))" + let hoursPart = "\(hours) \(hours.pluralized(singular: "hr", plural: "hrs"))" + guard hours > 0 else { - return "\(minutes) mins" + return minutesPart } - return "\(hours) hrs" + + return hoursPart } }