Home ProjectsThe Computus Engine Computing the date of Easter in AS3

Computing the date of Easter in AS3

by John

As I mentioned in my previous post, ‘computus‘ is the name given to the calculation of the date of Easter. What I didn’t get into was how to calculate it. There are dozens of algorithms for doing this but I’ve chosen the one from ‘Mapping Time’ by E.G.Richards. I like this one as it is relatively simple and it delivers a date in the Gregorian calendar.

function getEasterSunday(year:Number):Date
{
	var a = Math.floor(year / 100)
	var b = a - Math.floor(a / 4)
	var c = year % 19
	var d = (15 + 19*c + b - Math.floor((a + 1 - Math.floor((a+8) / 25)) / 3)) % 30
	var e = d - Math.floor((c+11*d) / 319)
	var s = 22 + e + (140004 - (year + Math.floor(year / 4))%7 + b - e) % 7

	var easter = new Date( year, 2, s, 0, 0, 0, 0 )
	return easter
}

The mechanics of the algorithm are fairly arcane and I won’t be going into them in this post but if you really want to know about epacts, Golden numbers, and Dominical letters then the Wikipedia entry on computus is very good.

I looked at quite a few Easter algorithms before settling on this one. The simplest ones always delivered a date in the Julian Calendar; the reason for this being that the Julian leap year rule is much simpler than the Gregorian. This is fine but the conversion from Julian to Gregorian always required some lookup table and that felt like a bit of a hack. I’ve tested the Richards algorithm against all the dates I can find and it seems to hold up fine.

You may also like

2 comments

Rosa February 9, 02009 - 8:05 pm

Hello! would you happen to have the formula you would use in excel to compute?
Thank you!

Reply
John February 9, 02009 - 10:32 pm

Hi Rosa, I don’t have a VB version of the code but the formula should work in any language. There’s some VB Easter code here if you prefer: http://www.cpearson.com/excel/holidays.htm

Regarding Excel, you need to be careful if you work with historical dates as Excel assumes 1900 was a leap year (it wasn’t). This causes some date calculations to blow up. The official MS docs are here: http://support.microsoft.com/kb/214058

Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.