mirror of
https://github.com/tonytins/amtkstat.git
synced 2026-10-24 05:32:54 -04:00
Improve train status formatting
This change adds proper singular/plural labels for minutes and hours in the lateness display, fixes green status text contrast for dark mode, and updates the README to credit the Amtrak.js models used as a base.
This commit is contained in:
parent
bf420b7480
commit
79176585b4
4 changed files with 16 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
7
Sources/AmtrakStatus/Helper.swift
Normal file
7
Sources/AmtrakStatus/Helper.swift
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import Foundation
|
||||
|
||||
extension Int {
|
||||
func pluralized(singular: String, plural: String) -> String {
|
||||
self == 1 ? singular : plural
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue