-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AstronomicalConstant] Calculations off by ~4.5hrs #27
Comments
Notes
static func _getmoonPhase(phase1: Double, phase2: Double) -> Int {
let percentages = [0, 0.25, 0.5, 0.75, 1]
var index = 0
if phase1 <= phase2 {
for i in 0...percentages.count {
if percentages[i] >= phase1, percentages[i] <= phase2 {
index = 2 * i
break
} else if percentages[i] > phase1 {
index = (2 * i) - 1
break
}
}
} else {
index = 0
}
return index % 8
} and to test let phases: [TinyMoon.MoonPhase] = [.newMoon, .waxingCrescent, .firstQuarter, .waxingGibbous, .fullMoon, .waningGibbous, .lastQuarter, .waningCrescent]
let date1 = TinyMoon.formatDate(year: 2024, month: 7, day: 20, timeZone: utcTimeZone)
let date2 = TinyMoon.formatDate(year: 2024, month: 07, day: 21, timeZone: utcTimeZone)
let date3 = TinyMoon.formatDate(year: 2024, month: 07, day: 22, timeZone: utcTimeZone)
let (start, end) = TinyMoon.Moon.julianStartAndEndOfDay(date: date2, timeZone: utcTimeZone)
let p1 = TinyMoon.AstronomicalConstant.getMoonPhase(julianDay: start).phase
let p2 = TinyMoon.AstronomicalConstant.getMoonPhase(julianDay: end).phase
print("p1", p1)
print("p2", p2)
let index = TinyMoon.AstronomicalConstant._getmoonPhase(phase1: p1, phase2: p2)
print(index)
print(phases[index])
``` |
Ended up finding MoonTool and converting the source code from Visual C to Swift. Much more accurate. |
Tests for these cases added here: TinyMoon/Tests/TinyMoonTests/TinyMoonTests.swift Lines 386 to 449 in 50b5dfd
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like the major moon phases have a ~4.5hr margin of error around midnight.
The following notes show what the
lib
/TinyMoon package show as the major moon phase, and thepst
andutc
columns show what timeanddate.com show for the actual moon phase.I was using this to test
To debug:
The text was updated successfully, but these errors were encountered: