Saturday, February 19, 2005

Calculating the Date of Easter

I'm working on a Ruby program where I have to convert from secular calendar dates to liturgical calendar dates. Central to this is calculating the date of Easter for a given year. I found the following helpful links:
Here is the Ruby code that I wrote:

SECONDS_IN_DAY = 60 * 60 * 24

def Bcp.calcEaster(year)
goldenNumber = year % 19 + 1

solarCorrection = (year - 1600) / 100 - (year - 1600) / 400
lunarCorrection = (((year - 1400) / 100) * 8) / 25

paschalFullMoon = (3 - (11 * goldenNumber) + solarCorrection - lunarCorrection) % 30
--paschalFullMoon if (paschalFullMoon == 29) || (paschalFullMoon == 28 && goldenNumber > 11)

dominicalNumber = (year + (year / 4) - (year / 100) + (year / 400)) % 7
daysToSunday = (4 - paschalFullMoon - dominicalNumber) % 7 + 1
easterOffset = paschalFullMoon + daysToSunday

return Time.local(year, "mar", 21) + (easterOffset * SECONDS_IN_DAY)
end

No comments: