Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Astronoby::Moon#current_phase_fraction
(#115)
While `#illuminated_fraction` already provides a valid information on how much the Moon seems illuminated as observed from the Earth, it doesn't help deduce the current phase name. When the Moon is 45% illuminated, it can be either the First Quarter or the Last Quarter, there is no way of knowing without calculating when is was the previous Full Moon and when is the next one. To help with this, we introduce `#current_phase_fraction`, based on the mean elongation, which is a number from 0 to 1 which always increase while we're getting closer to the next New Moon. As it is using `#mean_elongation`, the result is not extremely precise, however it is precise enough to deduce the current phase name for a given day. For a user wanting to get accurate phase times, it is preferred to use `::monthly_phase_events`. ```rb # ~ time of first quarter in December 2024 time = Time.utc(2024, 12, 8, 15, 26) Astronoby::Moon.new(time: time) .illuminated_fraction .round(2) # => 0.5 Astronoby::Moon.new(time: time) .current_phase_fraction .round(2) # => 0.26 # ~ time of last quarter in December 2024 time = Time.utc(2024, 12, 22, 22, 18) Astronoby::Moon.new(time: time) .illuminated_fraction .round(2) # => 0.5 Astronoby::Moon.new(time: time) .current_phase_fraction . round(2) # => 0.74 ``` Fixes #101
- Loading branch information