astronoby icon indicating copy to clipboard operation
astronoby copied to clipboard

Monthly Moon phases

Open rhannequin opened this issue 9 months ago • 1 comments

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:

  • February 2012 had only a Full Moon, Last Quarter and New Moon
  • May 2024 had two Last Quarter

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

rhannequin avatar May 22 '24 22:05 rhannequin