Commit 5ddfebfc by Demid Merzlyakov

CurrentWeather: Added approximateMoonset.

parent 5947ac81
......@@ -32,6 +32,8 @@ public struct CurrentWeather: Equatable, Hashable {
public var sunState: CelestialState? = .normal
public var moonrise: Date?
public var moonset: Date?
/// An approximate moonset value that can be used to draw animation when usual moonset is not available. Do not show this value to the user as actual time.
public var approximateMoonset: Date?
public var moonState: CelestialState? = .normal
public var moonPhase: MoonPhase? = .unknown
}
......
......@@ -26,7 +26,10 @@ public struct DailyWeather: Equatable, Hashable {
public var sunrise: Date?
public var sunset: Date?
public var sunState: CelestialState? = .normal
/// Note: this is when the moon rises in the evening. So, moonset < moonrise. It's different in CurrentWeather.
public var moonrise: Date?
/// Note: this is when the moon sets in the morning. So, moonset < moonrise. It's different in CurrentWeather.
public var moonset: Date?
public var moonState: CelestialState? = .normal
public var moonPhase: MoonPhase? = .unknown
......
......@@ -41,13 +41,30 @@ struct WdtLocation: Codable {
let dailyWeather = try dailySummaries?.toAppModel(timeZone: timeZone, updatedAt: updatedAt) ?? [DailyWeather]()
let hourlyWeather = try hourlySummaries?.toAppModel(timeZone: timeZone, updatedAt: updatedAt) ?? [HourlyWeather]()
if let firstDay = dailyWeather.first {
today?.minTemp = firstDay.minTemp
today?.maxTemp = firstDay.maxTemp
today?.precipitationProbability = firstDay.precipitationProbability
today?.sunState = firstDay.sunState
today?.moonState = firstDay.moonState
today?.moonPhase = firstDay.moonPhase
if let todayInDaily = dailyWeather.first {
today?.minTemp = todayInDaily.minTemp
today?.maxTemp = todayInDaily.maxTemp
today?.precipitationProbability = todayInDaily.precipitationProbability
today?.sunState = todayInDaily.sunState ?? .normal
}
let currentDate = Date()
if let moonDay = dailyWeather.first(where: {
let absTimeFromToday = fabs(currentDate.timeIntervalSince($0.date))
guard absTimeFromToday < TimeInterval(24 * 3600) else { // 24 hours else
return false
}
guard let moonset = $0.moonset else {
return false
}
return moonset > currentDate
}) {
#warning("Not implemented!")
//TODO: This logic is not correct, got to fix.
today?.moonState = moonDay.moonState ?? .normal
today?.moonPhase = moonDay.moonPhase
today?.moonrise = moonDay.moonrise
today?.moonset = moonDay.moonset
}
return Location(deviceLocation: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment