Skip to content

Commit

Permalink
Fix Moon monthly phase events calculation (#124)
Browse files Browse the repository at this point in the history
Noticed 'missing' first quarter phases for August, September and October 2025 in `Astronoby::Moon.monthly_phase_events`

Including 'the next' first quarter in the calculation ensures the coverage of a 'full cycle'.
  • Loading branch information
valeriy-sokoloff authored Jan 17, 2025
1 parent f8406a2 commit b8d9b8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/astronoby/events/moon_phases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def self.phases_for(year:, month:)
MoonPhase.first_quarter(new(year, month, :first_quarter, 0.25).time),
MoonPhase.full_moon(new(year, month, :full_moon, 0.5).time),
MoonPhase.last_quarter(new(year, month, :last_quarter, 0.75).time),
MoonPhase.new_moon(new(year, month, :new_moon, 1).time)
MoonPhase.new_moon(new(year, month, :new_moon, 1).time),
MoonPhase.first_quarter(new(year, month, :first_quarter, 1.25).time)
].select { _1.time.month == month }
end

Expand Down
8 changes: 8 additions & 0 deletions spec/astronoby/events/moon_phases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
# Result from IMCCE: 2024-01-25T17:54:01Z
end

it "returns correct phase events for 2025-08" do
moon_phases = described_class.phases_for(year: 2025, month: 8)
days_of_moon_phases = moon_phases.map { _1.time.day }

# Phases in August 2025 from IMCCE (days): 1, 9, 16, 23, 31
expect(days_of_moon_phases).to eq([1, 9, 16, 23, 31])
end

context "when there are more than 4 phases in a month" do
it "returns all of them" do
moon_phases = described_class.phases_for(year: 2024, month: 5)
Expand Down

0 comments on commit b8d9b8a

Please sign in to comment.