Skip to content

Commit

Permalink
Merge pull request #707 from OneBusAway/light-rail-error
Browse files Browse the repository at this point in the history
Handle scenarios where JSON k/v for `TimeWindow.to` is missing
  • Loading branch information
aaronbrethorst authored Jan 10, 2024
2 parents a30b0ac + c12fd3f commit f6e26f4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion OBAKitCore/Models/REST/References/ServiceAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ public class ServiceAlert: NSObject, Identifiable, Decodable, HasReferences {
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
from = Date(timeIntervalSince1970: TimeInterval(try container.decode(Int.self, forKey: .from)))
to = Date(timeIntervalSince1970: TimeInterval(try container.decode(Int.self, forKey: .to)))

if let rawToValue = try container.decodeIfPresent(Int.self, forKey: .to) {
to = Date(timeIntervalSince1970: TimeInterval(rawToValue))
}
else {
to = Date.distantFuture
}
}

public override func isEqual(_ object: Any?) -> Bool {
Expand Down

0 comments on commit f6e26f4

Please sign in to comment.