Skip to content

Instantly share code, notes, and snippets.

@rasmuschristensen
Created March 22, 2016 09:47
Show Gist options
  • Save rasmuschristensen/9b13b3478bdfa092ea68 to your computer and use it in GitHub Desktop.
Save rasmuschristensen/9b13b3478bdfa092ea68 to your computer and use it in GitHub Desktop.
Calculate easter day of a year. incl. leap year support
/// <summary>
/// Calculation based on https://da.wikipedia.org/wiki/P%C3%A5ske
/// </summary>
/// <param name="year"></param>
/// <returns></returns>
public DateTime GetEasterDateOfYear(int year)
{
int a = year % 19;
int b = (int)Math.Floor(year / 100m);//Heltal (rundet) ned) af aar / 100
int c = year % 100;
int d = (int)Math.Floor(b / 4m);
int e = b % 4;
int f = (int)Math.Floor((b + 8) / 25m);
int g = (int)Math.Floor((b - f + 1m) / 3);
int h = (19 * a + b - d - g + 15) % 30;
int i = (int)Math.Floor(c / 4m);
int k = c % 4;
int l = (32 + 2 * e + 2 * i - h - k) % 7;
int m = (int)Math.Floor((a + 11 * h + 22 * l) / 451m);
int n = (int)Math.Floor((h + l - 7 * m + 114) / 31m);
int p = (h + l - 7 * m + 114) % 31 + 1;
return new DateTime(year, n, p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment