Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE

1. Overview

In this tutorial, we’ll understand why the Easter date is complex to compute. Then, we’ll implement three algorithms to calculate it in Java: the Gauss, Butcher-Meeus, and Conway algorithms.

2. History of the Catholic Easter Sunday

Easter is a holiday that celebrates the resurrection of Jesus Christ from the dead. Easter’s timing was initially tied to the Jewish Passover, as the last supper of Jesus with his disciples was a Passover meal. However, during the first centuries, each Christian community could elect a date to celebrate it, leading to some controversy. The Council of Nicea in 325 finally standardized Easter’s definition: Easter Sunday is the first Sunday following the full moon after the vernal equinox.

Calculating Easter’s date is challenging because it depends on lunar and solar calendars, and lunar cycles don’t match solar ones. Thus, mathematical algorithms came in handy to determine Easter’s date.

3. Algorithms

Let’s point out that all algorithms focus on calculating the Catholic Easter date that uses the Gregorian calendar introduced by Pope Gregory XIII at the end of the 16th century. On the other hand, some churches, like the Russian Orthodox church, still use the Julian calendar to determine Easter’s date.

Now, let’s take a look at each of the algorithms.

3.1. Gauss Algorithm

Gauss, a famous German mathematician, was the first to tackle the problem at the beginning of the 19th century. His algorithm starts with tracking approximately the lunar orbit and then determines the exact offset to obtain a Sunday following the full moon.

Let’s have a look at it:

``````LocalDate computeEasterDateWithGaussAlgorithm(int year) {
int a = year % 19;
int b = year % 4;
int c = year % 7;
int k = year / 100;
int p = (13 + 8*k) / 25;
int q = k / 4;
int M = (15 - p + k - q) % 30;
int N = (4 + k - q) % 7;
int d = (19*a + M) % 30;
int e = (2*b + 4*c + 6*d + N) % 7;

if (d==29 && e == 6) {
return LocalDate.of(year, 4, 19);
} else if (d==28 && e==6 && ((11*M + 11)%30 < 10)) {
return LocalDate.of(year, 4, 18);
}

int H = 22 + d + e;
if (H <= 31) {
return LocalDate.of(year, 3, H);
}
return LocalDate.of(year, 4, H-31);
}``````

In this code:

• a represents the Golden Number, indicating the year’s position in the Metonic cycle
• b is associated with leap years, ensuring accurate adjustments given February’s length
• c keeps track of the calendar not having a leap year once a century
• p and q are intermediate variables, and calculating them leads to determining M and N, which represent adjustments regarding the epact, the difference between the lunar and solar years
• d is the number of days from March 21st till the Paschal full moon
• e is the number of days between the first day after the Paschal full moon and Easter Sunday

Lastly, there are two exceptions because the Paschal full moon can never occur on April 19th, and in rare cases, when a Metonic cycle would have its preceding full moon on the same day, which is not allowed.

Our method returns a LocalDate, as it’s a natural choice for representing a date without a timezone. Additionally, we can unit-test our method: for instance, with the year 2024, assuming we called our class EasterDateCalculator:

``````@Test
void givenEasterInMarch_whenComputeEasterDateWithGaussAlgorithm_thenCorrectResult() {
assertEquals(LocalDate.of(2024, 3, 31), new EasterDateCalculator().computeEasterDateWithGaussAlgorithm(2024));
}``````

3.2. Butcher-Meeus Algorithm

The origin of this algorithm is surprising: in 1876, an English paper called Nature received a letter from New York containing a method for Easter date calculation. One year later, Butcher, bishop of Meath, proved it was correct. Meeus popularized it in 1991 in his book Astronomical Algorithms.

Nowadays, it’s the most widely used in calendar-related software and applications.

The Butcher-Meeus algorithm enhances Gauss’s original method by incorporating refinements based on improved astronomical data and computational techniques.

Let’s implement it:

``````LocalDate computeEasterDateWithButcherMeeusAlgorithm(int year) {
int a = year % 19;
int b = year / 100;
int c = year % 100;
int d = b / 4;
int e = b % 4;
int f = (b + 8) / 25;
int g = (b - f + 1) / 3;
int h = (19*a + b - d - g + 15) % 30;
int i = c / 4;
int k = c % 4;
int l = (2*e + 2*i - h - k + 32) % 7;
int m = (a + 11*h + 22*l) / 451;
int t = h + l - 7*m + 114;
int n = t / 31;
int o = t % 31;
return LocalDate.of(year, n, o+1);
}``````

In this implementation:

• a is the Golden Number
• b is the secular year
• c is the vintage
• d and e handle leap century adjustments
• f and g relate to the proemptosis, an adjustment in the lunar equation to account for the Metonic’s cycle imperfection
• h represents the epact
• i and k assist in further leap-year adjustments
• l represents the first Sunday of January
• m is the final correcting term that allows us to compute Easter’s month and day

3.3. Conway Algorithm

A British mathematician named John Conway introduced a new original way to calculate Easter’s date in the second half of the 20th century. For this, he introduced the notion of pivotal days, a series of monthly dates that consistently occur on the same weekday, serving as fundamental reference points for calculating significant events.

Let’s code it:

``````LocalDate computeEasterDateWithConwayAlgorithm(int year) {
int s = year / 100;
int t = year % 100;
int a = t / 4;
int p = s % 4;
int x = (9 - 2*p) % 7;
int y = (x + t + a) % 7;
int g = year % 19;
int G = g + 1;
int b = s / 4;
int r = 8 * (s + 11) / 25;
int C = -s + b + r;
int d = (11*G + C) % 30;
d = (d + 30) % 30;
int h = (551 - 19*d + G) / 544;
int e = (50 - d - h) % 7;
int f = (e + y) % 7;
int R = 57 - d - f - h;

if (R <= 31) {
return LocalDate.of(year, 3, R);
}
return LocalDate.of(year, 4, R-31);
}``````

More precisely, in this code:

• s is the secular year, and t the vintage
• a assists in determining leap years within a century
• x is the secular pivotal day
• y is the current year’s pivotal day
• G denotes the Golden Number
• b relates to metemptosis, a correction to the lunar equation to prevent Easter’s date from falling one day too late
• r is the proemptosis
• C is the secular correction
• d determines the Paschal full moon’s day
• h accounts for epact-related exceptions
• e measures the deviation between the Paschal full moon and the pivotal day
• lastly, f represents the day of the week of the Paschal full moon, allowing us the eventual calculation of Easter’s date

4. Conclusion

In this article, we understood why algorithms are needed to calculate Easter’s date and implemented the three most famous ones. Simplifications of the Gauss and Butcher-Meeus algorithms exist to calculate Easter’s date in the Julian calendar. However, this isn’t the end of the story for churches that still use the Julian calendar. Nearly all countries use the Gregorian calendar, so in the end, they must convert the date to this calendar.

As always, the code is available over on GitHub.

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.