Calculate Easter and other holidays in Erlang
I wrote a small library for calculating Easter and other holidays in Erlang. Here's how I did it and what I learned.

On a whim, I created an Erlang module for calculating holidays, and things were going okay until it came to Easter. Have you ever tried to calculate Easter? It's surprisingly difficult.
Easter doesn't occur on the same day of the month, or on the Xth Sunday, or anything that simple like most holidays. It's based on the occurrence of a particular full moon, among other things. I started by trying to recreate this explanation, but trying to recreate it in code got pretty ugly pretty quick.
Here's what I came up with, but it's only the Catholic (aka western) date. The Orthodox (aka eastern) date is a completely different calculation, which I implemented with the help of Meeus's Julian algorithm.
There's a heavy use of div
instead of /
because the former behaves similar to integer arithmetic in C#, whereas the latter behaves like floating point arithmetic.
For example, 7 div 4 == 1
but 7 / 4 == 1.75
.
The Importance of Tests
I ended up converting an algorithm in C#, which was a conversion from c++, which was in turn converted from Pascal code, so unit tests seemed like a good idea. I'm reasonably sure it's behaving!
Since we can pass functions around in Erlang, I added a function that allows for passing a date and a list of holidays to test it against.
If you use Erlang and you need to know if a date is a holiday, try this out. If you have your own holidays to add, open an issue or PR, or just leave a comment below. Contributions welcome!
Spread the Word