Last active
December 18, 2015 01:49
-
-
Save philippfranke/5706602 to your computer and use it in GitHub Desktop.
It returns the date of easter - see unit test: http://jsfiddle.net/6ZtTP/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unit testing: http://jsfiddle.net/6ZtTP/ | |
function getEaster(year) { | |
"use strict"; | |
var a, k, m, d, s, r, og, sz, oe, os, date; | |
date = new Date(year,2,1,0,0); | |
// Moon parameter | |
a = year % 19; | |
// Secular number | |
k = Math.floor(year / 100); | |
// Secular Moon shift | |
m = 15 + Math.floor((3 * k + 3) / 4) - Math.floor((8 * k + 13) / 25); | |
// Seed for 1st full Moon in spring | |
d = (19 * a + m) % 30; | |
// Secular sun shift | |
s = 2 - Math.floor((3 * k + 3) / 4); | |
// Calendarian correction quantity | |
r = Math.floor((d + Math.floor(a / 11)) / 29); | |
// Easter limit | |
og = 21 + d - r; | |
// 1st sunday in March | |
sz = 7 - (year + Math.floor(year / 4) + s) % 7; | |
// Distance Easter sunday from Easter limit in days | |
oe = 7 - (og - sz) % 7;// Distance Easter sunday from Easter limit in days | |
// Easter sunday as number of days in March | |
os = (og + oe) ; | |
// Convert to dare | |
date.setDate(date.getDate() + os - 1); | |
return date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment