A function that generates a Date object for Western Easter Sunday for any given year. Researched and developed out sheer curiosity of the Easter’s seemingly random date.

Example usage of a input that once submitted returns the year of date of Easter for a given year (between -271820 and 275760).

The date of Easter will appear here.

Uses the algorithm as published in The Date of Easter (on aa.usno.navy.mil, Oct 2007). The algorithm is credited to J. M. Oudin (1940) and is reprinted in the Explanatory Supplement to the Astronomical Almanac, ed. P. K. Seidelmann (1992). See Chapter 12, “Calendars”, by L. E. Doggett.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
function easterDate( y ) // Takes a given year (y) then returns Date object of Easter Sunday { /* Easter Date Function for JavaScript implemented by Furgelnod ( https://furgelnod.com ) Using algorithm published at The Date of Easter (on aa.usno.navy.mil, Oct 2007) (https://web.archive.org/web/20071015045929/http://aa.usno.navy.mil/faq/docs/easter.php) The algorithm is credited to J.-M. Oudin (1940) and is reprinted in the Explanatory Supplement to the Astronomical Almanac, ed. P. K. Seidelmann (1992). See Chapter 12, "Calendars", by L. E. Doggett. */ try { y = Number( y ); if ( y != y ) { throw new TypeError( "Value must be a number." ); } else if ( y > 275760 || y < -271820 ) { throw new RangeError( "Value be between -271820 and 275760 due to technical limitations of Date constructor." ); } } catch ( e ) { console.error( e ); } y = Math.floor( y ); var c = Math.floor( y / 100 ); var n = y - 19 * Math.floor( y / 19 ); var k = Math.floor( ( c - 17 ) / 25 ); var i = c - Math.floor( c / 4 ) - Math.floor( ( c - k ) / 3 ) + 19 * n + 15; i = i - 30 * Math.floor( i / 30 ); i = i - Math.floor( i / 28 ) * ( 1 - Math.floor( i / 28 ) * Math.floor( 29 / ( i + 1 ) ) * Math.floor( ( 21 - n ) / 11 ) ); var j = y + Math.floor( y / 4 ) + i + 2 - c + Math.floor( c / 4 ); j = j - 7 * Math.floor( j / 7 ); var l = i - j; var m = 3 + Math.floor( ( l + 40 ) / 44 ); var d = l + 28 - 31 * Math.floor( m / 4 ); var z = new Date(); z.setFullYear( y, m-1, d ); return z; } // -- easterDate |