UNPKG

@pacote/computus

Version:

Determine the calendar date of the Easter holiday.

72 lines 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.gregorian = gregorian; exports.julian = julian; function integerDivision(dividend, divider) { return Math.floor(dividend / divider); } /** * This function takes a year and returns a `Date` object with the Gregorian * calendar Easter day on that year at midnight. * * The function uses a version of the Meeus/Jones/Butcher algorithm published * by _New Scientist_ on 30 March 1961. * * @example * ```typescript * import { gregorian } from '@pacote/computus' * * gregorian(2020) // .toLocaleDateString() => '4/12/2020' * ``` * * @param year Year. * * @returns Easter date for the provided year. */ function gregorian(year) { var a = year % 19; var b = integerDivision(year, 100); var c = year % 100; var d = integerDivision(b, 4); var e = b % 4; var g = integerDivision(8 * b + c, 25); var h = (19 * a + b - d - g + 15) % 30; var i = integerDivision(c, 4); var k = c % 4; var l = (2 * e + 2 * i - h - k + 32) % 7; var m = integerDivision(a + 11 * h + 19 * l, 433); var n = integerDivision(h + l - 7 * m + 90, 25); var p = (h + l - 7 * m + 33 * n + 19) % 32; return new Date(year, n - 1, p); } /** * This function takes a year and returns a `Date` object with the Eastern * Orthodox Easter day on that year at midnight. Please note that this date * is returned for the Gregorian calendar, 13 days (as of 1900 through 2099) * after the Julian date. * * The function implements the Jean Meeus algorithm from his book * _Astronomical Algorithms_ (1991). * * @example * ```typescript * import { julian } from '@pacote/computus' * * julian(2020) // .toLocaleDateString() => '4/19/2020' * ``` * * @param year Year. * * @returns Eastern Orthodox Easter date for the provided year. */ function julian(year) { var a = year % 4; var b = year % 7; var c = year % 19; var d = (19 * c + 15) % 30; var e = (2 * a + 4 * b - d + 34) % 7; var month = integerDivision(d + e + 114, 31); var day = ((d + e + 114) % 31) + 1; return new Date(year, month - 1, day + 13); } //# sourceMappingURL=index.js.map