Skip to content

Instantly share code, notes, and snippets.

@AldoMX
Last active January 3, 2023 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AldoMX/7f226012529cacb0ed2308166c4ee71a to your computer and use it in GitHub Desktop.
Save AldoMX/7f226012529cacb0ed2308166c4ee71a to your computer and use it in GitHub Desktop.
JavaScript implementation of Easter Algorithms
// Algorithm by Tom O’Beirne
// (1961) Puzzles and Paradoxes. New Scientist, No. 228, p. 829, Table 1
// https://books.google.com/books?id=zfzhCoOHurwC&pg=PA829
//
// Implementation in JavaScript by Aldo Fregoso.
// Released under public domain without any kind of warranty or support.
//
function oBeirnesEasterAlgo(x) {
assert(x != 0, "Year zero does not exist in the Anno Domini (AD) calendar year system.");
if (x <= 1582) {
console.warn("Gregorian Calendar took effect on October, 1582.");
}
const a = x % 19;
const b = ~~(x / 100);
const c = x % 100;
const d = ~~(b / 4);
const e = b % 4;
const g = ~~((8 * b + 13) / 25);
const h = (19 * a + b - d - g + 15) % 30;
const i = ~~(c / 4);
const k = c % 4;
const l = (2 * e + 2 * i - h - k + 32) % 7;
const m = ~~((a + 11 * h + 19 * l) / 433);
const n = ~~((h + l - 7 * m + 90) / 25);
const p = (h + l - 7 * m + 33 * n + 19) % 32;
const year = x.toString(10).padStart(4, '0');
const month = n.toString(10).padStart(2, '0');
const day = p.toString(10).padStart(2, '0');
return `${year}-${month}-${day}`;
}
// Algorithm by Jean Meeus
// (1991) Astronomical Algorithms, p. 69
// https://books.google.com/books?id=PU7XxnmcDwYC&pg=PA69
//
// Implementation in JavaScript by Aldo Fregoso.
// Released under public domain without any kind of warranty or support.
//
function meeusJulianEasterAlgo(x) {
assert(x != 0, "Year zero does not exist in the Anno Domini (AD) calendar year system.");
if (x < -45) {
console.warn("Julian Calendar took effect on January 1st, 45 BC.");
}
if (x < 33) {
console.info('Resurrection Sunday most likely happened at April 3rd, AD 33.');
}
if (x < 200) {
console.warn('The algorithm returns non-Sundays for years < 200.');
}
const a = x % 4;
const b = x % 7;
const c = x % 19;
const d = (19 * c + 15) % 30;
const e = (2 * a + 4 * b - d + 34) % 7;
const f = d + e + 114;
const g = ~~(f / 31);
const h = (f % 31) + 1;
const year = x.toString(10).padStart(4, '0');
const month = g.toString(10).padStart(2, '0');
const day = h.toString(10).padStart(2, '0');
return `${year}-${month}-${day}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment