rhannequin / astronoby

Ruby library based on astronomy and astrometry books
https://dev.to/rhannequin/series/17782
MIT License
59 stars 2 forks source link

Monthly Moon phases #82

Closed rhannequin closed 6 months ago

rhannequin commented 6 months ago

This change introduces multiple new objects to be able to get all the phase times for a given month.

The Moon phases are: New Moon, First Quarter, Full Moon and Last Quarter.

Because the average lunar month is approximatively 29.5 days, most of the time there are only one of each phase per month. This also means that in some configuration, it is possible to have only 3 phases in a month, or to have a phase happening twice in a month, giving 5 phases:

For this reason, this change generates an array of unknown length, containing a Astronoby::MoonPhase object for each phase happening in the month.

The algorithm provided by Jean Meeus report having a mean margin error of 3 seconds, which has been confirmed from a few comparisons with the IMCCE.

The new Astronoby::MoonPhase object only exposes the time and phase name of the event. In the future, it could be interesting to add more methods like #full_moon? or similar.

Astronoby::Events::MoonPhases contains all the logic and exposes the final list. This list can also be accessed through Astronoby::Moon for ease of use.

moon_phases = Astronoby::Moon.monthly_phase_events(year: 2024, month: 1)

moon_phases.first.phase
# => :last_quarter

moon_phases.first.time
# => 2024-01-04 03:30:26 UTC
trevorturk commented 6 months ago

🙌🥇🥳