SwiftySuncalc
SwiftySuncalc copied to clipboard
Phase Data Seems Odd
I've not quite figured this one out, but I have not dug into the algorithm. If I pass 15 consecutive dates into the moon illumination function, i would expect the return value for "phase" to progress through multiple phases. What I am getting is quite different.
// basic pseudo-code of call interation
var sunMoon: SwiftySuncalc! = SwiftySuncalc()
for date in dates { // 15 consecutive days of Dates in dates
let dict = sunMoon.getMoonIllumination(date: date)
print(dict["phase"])
}
What I am getting is something like this:
0.3497411806334137
0.37585891141293126
0.3758589140085576
0.37585891487953565
0.37585891703961904
0.375858919217154
0.37585892094173023
0.3758589222482511
0.3758589244083345
... and similar through the remaining
I found it odd that the first iteration produced a difference of ~.03 but the next series of iterations barely moved the needle. In theory, the moon phase should progress through a little over half a full cycle in 15 days. Any thoughts? It's certainly possible that I did not interpret the usage of the phase correctly - i.e. does it need to be used in combination with the angle to get the phase values 0.0 - 1.0
I think this is because of this part of code:
if date < Date() {
d = toDays(date: date)
} else {
d = toDays(date: Date())
}
So, if you want to get the moon illumination for tomorrow or later, you'll always get today's data.
Fix: just remove these lines from the getMoonIllumination function.