This commit is contained in:
Trey t
2026-01-19 23:53:37 -06:00
parent 19dd1791f1
commit 11adfc10dd
8 changed files with 126 additions and 42 deletions

View File

@@ -47,6 +47,7 @@ actor BootstrapService {
let primary_team_abbrevs: [String]
let year_opened: Int?
let timezone_identifier: String?
let image_url: String?
}
private struct JSONCanonicalTeam: Codable {
@@ -66,8 +67,9 @@ actor BootstrapService {
let canonical_id: String
let sport: String
let season: String
let date: String
let time: String?
let game_datetime_utc: String? // ISO 8601 format (new canonical format)
let date: String? // Legacy format (deprecated)
let time: String? // Legacy format (deprecated)
let home_team_canonical_id: String
let away_team_canonical_id: String
let stadium_canonical_id: String
@@ -215,6 +217,7 @@ actor BootstrapService {
longitude: jsonStadium.longitude,
capacity: jsonStadium.capacity,
yearOpened: jsonStadium.year_opened,
imageURL: jsonStadium.image_url,
sport: jsonStadium.sport,
timezoneIdentifier: jsonStadium.timezone_identifier
)
@@ -423,10 +426,18 @@ actor BootstrapService {
guard !seenGameIds.contains(jsonGame.canonical_id) else { continue }
seenGameIds.insert(jsonGame.canonical_id)
guard let dateTime = parseDateTime(date: jsonGame.date, time: jsonGame.time ?? "7:00p") else {
continue
// Parse datetime: prefer ISO 8601 format, fall back to legacy date+time
let dateTime: Date?
if let iso8601String = jsonGame.game_datetime_utc {
dateTime = parseISO8601(iso8601String)
} else if let date = jsonGame.date {
dateTime = parseDateTime(date: date, time: jsonGame.time ?? "7:00p")
} else {
dateTime = nil
}
guard let dateTime else { continue }
let game = CanonicalGame(
canonicalId: jsonGame.canonical_id,
schemaVersion: SchemaVersion.current,
@@ -677,6 +688,13 @@ actor BootstrapService {
return "venue_unknown_\(venue.lowercased().replacingOccurrences(of: " ", with: "_"))"
}
nonisolated private func parseISO8601(_ string: String) -> Date? {
// Handle ISO 8601 format: "2026-03-01T18:05:00Z"
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime]
return formatter.date(from: string)
}
nonisolated private func parseDateTime(date: String, time: String) -> Date? {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")