Skip to content

[2.3.0] Accurate phase (MoonTool)

Compare
Choose a tag to compare
@mannylopez mannylopez released this 13 Jul 00:38
· 23 commits to main since this release
50b5dfd

What's Changed

TinyMoon is now a lot more accurate. SunCalc has known issues in it's Moon calculations. In my tests, I discovered two bugs

1//
The phase value "jumped" around the full moon. This happened when the angle switched from positive to negative and the ternary operator caused a non linear jump, when phase should be gradual.

// https://github.com/mourner/suncalc/blob/master/suncalc.js#L245
phase: 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI,

This is what I mean by "jump" and not gradual:

...
phase = 0.47
phase = 0.48
phase = 0.51
phase = 0.50
phase = 0.49
...

2//
Also noticed that moon phases are off by about 4.5hrs. Documented here: #27

Solution

I found the excellent MoonTool program, https://www.fourmilab.ch/moontoolw/, that allowed me to download the source code. I converted the C code to Swift and removed the non-relevant parts. I then replaced phase calculations to use the new MoonTool-based method and all tests passed.

I removed most of SunCalc's formulas.

Changelog

Full Changelog: 2.2.0...2.3.0