diff --git a/Sources/Weather/Models/Weather.swift b/Sources/Weather/Models/Weather.swift index ec034ad..3d48666 100644 --- a/Sources/Weather/Models/Weather.swift +++ b/Sources/Weather/Models/Weather.swift @@ -56,7 +56,7 @@ extension Weather { } public var forecasts: [Forecast] { - let now = Date() + let now: Date = .oneHourAgo return timeSeries.sorted(by: { $0.validTime < $1.validTime }) .filter { forecast -> Bool in forecast.validTime >= now @@ -64,13 +64,20 @@ extension Weather { } /// - Returns: The most relevant `Forecast` - public func get(by date: Date = .init(timeIntervalSinceNow: 60 * 60 * -1)) -> Forecast? { + public func get(by date: Date? = nil) -> Forecast? { + let date: Date = date ?? .oneHourAgo return forecasts.first { forecast -> Bool in forecast.validTime >= date } } } +extension Date { + fileprivate static var oneHourAgo: Date { + return Date(timeIntervalSinceNow: 60 * 60 * -1) + } +} + extension Weather { public static func publisher(latitude: Double, longitude: Double) -> WeatherPublisher { return WeatherPublisher(