Method: Astro::Moon.phasehunt

Defined in:
lib/astro/moon.rb

.phasehunt(date = nil) ⇒ Object

Finds the key dates of the specified lunar month. Takes a DateTime object (or creates one using now() function). Returns a PhaseHunt struct instance. (see Constants section)

# find the date/time of the full moon in this lunar month
Astro::Moon.phasehunt.moon_full.strftime("%D %T %Z") \
# => "03/04/07 02:17:40 +0300"


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/astro/moon.rb', line 81

def phasehunt(date = nil)
    date = DateTime.now if !date
    sdate = date.ajd

    adate = sdate - 45
    ad1 = DateTime.jd(adate)

    k1 = ((ad1.year + ((ad1.month - 1) *
                       (1.0 / 12.0)) - 1900) * 12.3685).floor

    adate = nt1 = meanphase(adate,  k1)

    while true
        adate += SYNMONTH
        k2 = k1 + 1
        nt2 = meanphase(adate, k2)
        break if nt1 <= sdate && nt2 > sdate
        nt1 = nt2
        k1 = k2  
    end

    return PhaseHunt.new(*[
                         truephase(k1, 0.0),
                         truephase(k1, 0.25),
                         truephase(k1, 0.5),
                         truephase(k1, 0.75),
                         truephase(k2, 0.0)
    ].map {
        |_| _.new_offset(date.offset)
    })
end