by Jim Karabatsos - GUI Computing
One of the really difficult things about setting up production systems it to create processing calendars - which days are workdays and which are not. Many holidays are pretty straightforward (as long as you are talking just one location - things get much more complicated if you need to write international software). Australia Day always falls on January 26, the Melbourne Cup is the first Tuesday in November and so on.
In countries with predominantly Christian populations such as Australia, the real fly in the ointment is Easter. It seems to move around with no discernible pattern. Yet there must be some rules; after all, someone calculates Easter for each year.
Well, I'm afraid I don't know how it works for the Catholic and later churches. In case you hadn't noticed, I come from a Greek background and it was in a discussion with an aunt of my wife that the subject of Easter dates came up. She mentioned that another relative of hers in the USA had developed a formula for calculating the Orthodox Easter and she produces a scrap of paper that contained a cryptic formula using a notation I was not familiar with.
It did, however, rouse my curiosity, so much so that I began playing around with it. It turns out that the author had used a subscripted numeric suffix to indicate the modulus operation. Who knows, maybe that's standard mathematical notation; I'm no mathematician. Anyway, I wrote something that actually works, so I thought I'd share it with you because (a) you might live in an Orthodox country and might find it useful or (b) you might know a similar technique for calculating the Catholic Easter in which case I would ask you please to share it with me.
Here is the code. Given a year, it will return the date of the Orthodox Easter Sunday. The "T" variable is just used to evaluate a common term once. The test for years before 1924 relates to a calendar change in 1923. The formula calculates the day in April that corresponds to Orthodox Easter Sunday. This can be more than 30, signifying May. For dates before 1924, it can also be < 1, signifying March. These conditions are also handled in the code.
Function OrthodoxEasterSunday(ByVal Y As Integer) As Date Dim T As Long Dim DD As Integer Dim MM As Integer T = (19 * (Y Mod 19) + 16) Mod 30 DD = 3 + T + (2 * (Y Mod 4) + 4 * (Y Mod 7) + 6 * T) Mod 7 If Y < 1924 Then DD = DD - 13 If DD > 30 Then DD = DD - 30 MM = 5 Else MM = 4 End If If DD < 1 Then DD = DD + 31 MM = 3 End If OrthodoxEasterSunday = DateSerial(Y, MM, DD) End Function
I always find these sorts of algorithms intriguing. How on earth does anybody actually develop one of these?
Remember, if you know how to calculate the Catholic Easter, I'd be very interested in hearing from you.