feat: add timezone support for stadium-local game times
Adds timeZoneIdentifier to Stadium model and localGameTime/localGameTimeShort computed properties to RichGame. Game times can now display in venue local timezone. Also adds timezone field to Python StadiumInfo dataclass with example entries for Pacific, Central, Mountain, and Toronto timezones. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -91,4 +91,20 @@ struct RichGame: Identifiable, Hashable, Codable {
|
||||
var venueDescription: String {
|
||||
"\(stadium.name), \(stadium.city)"
|
||||
}
|
||||
|
||||
/// Game time formatted in the stadium's local timezone with timezone indicator
|
||||
var localGameTime: String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "h:mm a z"
|
||||
formatter.timeZone = stadium.timeZone ?? .current
|
||||
return formatter.string(from: game.dateTime)
|
||||
}
|
||||
|
||||
/// Game time formatted in the stadium's local timezone without timezone indicator
|
||||
var localGameTimeShort: String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "h:mm a"
|
||||
formatter.timeZone = stadium.timeZone ?? .current
|
||||
return formatter.string(from: game.dateTime)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ struct Stadium: Identifiable, Codable, Hashable {
|
||||
let sport: Sport
|
||||
let yearOpened: Int?
|
||||
let imageURL: URL?
|
||||
let timeZoneIdentifier: String?
|
||||
|
||||
init(
|
||||
id: String,
|
||||
@@ -28,7 +29,8 @@ struct Stadium: Identifiable, Codable, Hashable {
|
||||
capacity: Int,
|
||||
sport: Sport,
|
||||
yearOpened: Int? = nil,
|
||||
imageURL: URL? = nil
|
||||
imageURL: URL? = nil,
|
||||
timeZoneIdentifier: String? = nil
|
||||
) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
@@ -40,6 +42,11 @@ struct Stadium: Identifiable, Codable, Hashable {
|
||||
self.sport = sport
|
||||
self.yearOpened = yearOpened
|
||||
self.imageURL = imageURL
|
||||
self.timeZoneIdentifier = timeZoneIdentifier
|
||||
}
|
||||
|
||||
var timeZone: TimeZone? {
|
||||
timeZoneIdentifier.flatMap { TimeZone(identifier: $0) }
|
||||
}
|
||||
|
||||
var location: CLLocation {
|
||||
|
||||
Reference in New Issue
Block a user